/* VecinIA Administrator desktop demo — Luminous Blue / sage / clay */
:root {
  --blue: #1B6EF3;
  --blue-deep: #0B3FAE;
  --blue-soft: #D9E8FF;
  --sage: #E7F0E8;
  --sage-deep: #6F8F78;
  --clay: #C46A3A;
  --ink: #14201A;
  --muted: #5A6B62;
  --white: #fff;
  --line: rgba(20, 32, 26, 0.1);
  --sidebar: #0e2a6b;
  --panel: rgba(255, 255, 255, 0.92);
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; }
a { color: var(--blue-deep); }

/* Light copy deterrence (login/forms stay selectable) */
body { -webkit-user-select: none; user-select: none; }
input, textarea, select, [contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

/* Author display:grid/flex beats the UA [hidden] rule — force hide. */
[hidden] { display: none !important; }

.skip-link {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; left: 12px; top: 12px; width: auto; height: auto; margin: 0;
  padding: 10px 16px; clip: auto; overflow: visible; z-index: 100;
  background: var(--blue-deep); color: #fff; font-weight: 700; border-radius: 8px;
}

html { overflow-x: clip; }

body {
  min-height: 100dvh;
  overflow-x: clip;
  background:
    radial-gradient(900px 480px at 0% 0%, #c5d8ff 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #d5e8d8 0%, transparent 50%),
    linear-gradient(165deg, #e8eef8 0%, #f2f6f3 45%, #e6efe9 100%);
  color: var(--ink);
}

.brand-name {
  font-family: "Fraunces", serif;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--blue-deep);
}
.brand-name span { color: var(--clay); }

.logo-mark {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(145deg, var(--blue), var(--blue-deep));
  display: grid; place-items: center;
  box-shadow: 0 10px 24px rgba(27,110,243,.35);
}
.logo-mark svg { width: 32px; height: 32px; }
.logo-mark.sm { width: 36px; height: 36px; border-radius: 10px; }
.logo-mark.sm svg { width: 20px; height: 20px; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; cursor: pointer;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; touch-action: manipulation;
}
.btn.primary {
  background: linear-gradient(145deg, var(--blue), var(--blue-deep));
  color: #fff; box-shadow: 0 10px 24px rgba(27,110,243,.3);
}
.btn.ghost {
  background: #fff; border: 1.5px solid var(--line); color: var(--ink);
}
.btn:focus-visible { outline: 3px solid var(--clay); outline-offset: 2px; }

.menu-toggle,
.sidebar-close {
  display: none;
  align-items: center; justify-content: center;
  width: 44px; height: 44px; min-width: 44px; padding: 0;
  border: 0; border-radius: 12px; cursor: pointer; touch-action: manipulation;
  color: var(--blue-deep); background: #fff; border: 1.5px solid var(--line);
  flex-shrink: 0;
}
.sidebar-close {
  margin-left: auto; color: #e8eefc;
  background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.18);
}
.compact-toggle { display: none; font-size: 13px; padding: 10px 12px; }
.top-leading { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.top-titles { min-width: 0; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 40;
  background: rgba(14, 32, 26, 0.45);
  -webkit-tap-highlight-color: transparent;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin: 0 -2px;
}

/* Login */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.login-panel {
  width: min(480px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(11,63,174,.12);
  animation: rise .45s cubic-bezier(.2,.8,.2,1) both;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo-mark { margin: 0 auto 12px; }
.login-brand .brand-name { font-size: 36px; }
.login-tag { color: var(--muted); margin-top: 8px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.login-form select, .login-form input {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff;
}
.persona-note {
  font-size: 13px; color: var(--muted); line-height: 1.45;
  background: rgba(27,110,243,.06); border-radius: 12px; padding: 12px 14px;
}
.muted-optional { font-weight: 500; opacity: .75; }
.pass-hint { font-size: 12px; color: var(--muted); }
.pass-hint code { background: var(--sage); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.login-links {
  display: flex; flex-wrap: wrap; gap: 12px 18px; justify-content: center;
  font-size: 13px; font-weight: 600;
}

/* Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: linear-gradient(180deg, #0b3fae 0%, #0a2f82 55%, #0e274f 100%);
  color: #e8eefc;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar .brand-name { color: #fff; font-size: 22px; }
.sidebar .brand-name span { color: #F2B27A; }
.sidebar-sub { font-size: 12px; opacity: .75; margin-top: 2px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav button {
  text-align: left; border: 0; background: transparent; color: inherit;
  padding: 12px 12px; min-height: 44px; border-radius: 12px; font-weight: 600;
  cursor: pointer; opacity: .88; touch-action: manipulation;
}
.side-nav button:hover { background: rgba(255,255,255,.08); }
.side-nav button.active {
  background: rgba(255,255,255,.14);
  opacity: 1;
  box-shadow: inset 3px 0 0 #F2B27A;
}
.side-nav button:focus-visible { outline: 2px solid #F2B27A; outline-offset: 1px; }

.sidebar-foot {
  display: flex; flex-direction: column; gap: 8px;
  font-size: 13px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-foot a, .sidebar-foot .linkish {
  color: #cfe0ff; background: none; border: 0; text-align: left;
  cursor: pointer; font-weight: 600; padding: 10px 0; min-height: 44px;
  display: inline-flex; align-items: center; touch-action: manipulation;
}

.main-wrap { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.top {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; padding: 22px 28px 10px; flex-wrap: wrap;
}
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--sage-deep);
}
.top h1 {
  font-family: "Fraunces", serif; font-size: 28px; letter-spacing: -0.02em;
  color: var(--blue-deep); margin-top: 4px;
}
.top-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.assoc-switch {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase;
}
.assoc-switch select {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fff; min-width: 180px;
}
.user-chip {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 14px; display: flex; flex-direction: column; gap: 2px;
}
.user-chip span { font-size: 12px; color: var(--muted); }

.main {
  padding: 8px 28px 40px;
  min-width: 0;
  max-width: 100%;
  /* Opacity-only: transform on .main makes position:fixed descendants use main as CB. */
  animation: rise-fade .35s ease both;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px;
  animation: rise .4s cubic-bezier(.2,.8,.2,1) both;
}
.stat:nth-child(2) { animation-delay: .05s; }
.stat:nth-child(3) { animation-delay: .1s; }
.stat:nth-child(4) { animation-delay: .15s; }
.stat .label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value {
  font-family: "Fraunces", serif; font-size: 28px; color: var(--blue-deep); margin-top: 6px;
}
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel {
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
  padding: 18px; margin-bottom: 16px;
  min-width: 0; max-width: 100%;
}
.panel h2 {
  font-size: 13px; font-weight: 700; color: var(--muted);
  letter-spacing: .05em; text-transform: uppercase; margin-bottom: 12px;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.pill {
  display: inline-flex; font-size: 11px; font-weight: 700;
  padding: 4px 9px; border-radius: 999px;
}
.pill.work { background: rgba(196,106,58,.14); color: var(--clay); }
.pill.open { background: rgba(27,110,243,.12); color: var(--blue-deep); }
.pill.done { background: rgba(61,154,106,.15); color: #2d7a52; }

.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  align-items: start;
}
.kanban-col {
  background: rgba(231,240,232,.55);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  min-height: 220px;
}
.kanban-col h3 {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); margin-bottom: 10px;
}
.task-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 8px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.task-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(11,63,174,.08);
}
.task-card strong { display: block; font-size: 14px; margin-bottom: 4px; }
.task-card p { font-size: 12px; color: var(--muted); }

.muted { color: var(--muted); font-size: 13px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Finance forms & allocation preview */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.form-grid label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.form-grid label.span-2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fff; color: var(--ink); font-weight: 500; text-transform: none; letter-spacing: 0;
}
.form-grid textarea { min-height: 72px; resize: vertical; }
.alloc-preview {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(231,240,232,.35);
}
.alloc-preview .table-scroll {
  border: 0; border-radius: 0; margin: 0;
}
.alloc-preview .preview-head {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; background: rgba(27,110,243,.06);
  border-bottom: 1px solid var(--line);
}
.alloc-preview .preview-head strong {
  font-family: "Fraunces", serif; color: var(--blue-deep); font-size: 18px;
}
.alloc-preview .table { background: #fff; }
.alloc-preview .table tbody tr:hover { background: rgba(27,110,243,.04); }
.formula-hint {
  font-size: 13px; color: var(--muted); line-height: 1.45;
  margin: 8px 0 0; padding: 10px 12px;
  background: rgba(27,110,243,.05); border-radius: 10px;
}
.formula-hint code {
  font-size: 12px; background: #fff; border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px;
}
.split-tabs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.split-tabs button {
  border: 1.5px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 12px; font-weight: 600; cursor: pointer; color: var(--ink);
}
.split-tabs button.active {
  background: var(--blue-soft); border-color: transparent; color: var(--blue-deep);
}
.unit-drill {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px;
}
.unit-chip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 12px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.unit-chip.active {
  background: linear-gradient(145deg, var(--blue), var(--blue-deep));
  color: #fff; border-color: transparent;
}
.unit-chip .amt { display: block; font-size: 11px; font-weight: 500; opacity: .85; margin-top: 2px; }
.source-pill.spv { background: rgba(27,110,243,.12); color: var(--blue-deep); }
.source-pill.manual { background: rgba(111,143,120,.18); color: #3d5c45; }
/* Flex + overflow so tall dialogs stay framed on ~700–900px laptop heights.
   Mounted under #modal-layer on body (see admin.js) so fixed covers the viewport. */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(14,32,26,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 80; padding: 16px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: rise-fade .2s ease both;
}
.modal-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden; margin: auto;
  background: #fff; border-radius: 18px; border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(11,63,174,.2);
}
.modal-card-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  overscroll-behavior: contain; padding: 20px 20px 12px;
}
.modal-card h2 {
  font-family: "Fraunces", serif; font-size: 22px; color: var(--blue-deep);
  text-transform: none; letter-spacing: -0.02em; margin-bottom: 6px;
}
.modal-actions {
  flex-shrink: 0;
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end;
  padding: 12px 20px 16px; border-top: 1px solid var(--line);
  background: #fff;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes rise-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* —— Tablet / laptop mid: keep desktop shell, tighten grids —— */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .kanban { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* —— Narrow (<1024): drawer sidebar, stacked chrome, scrollable tables —— */
@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    overflow-x: clip;
  }

  .menu-toggle,
  .sidebar-close { display: inline-flex; }
  .compact-toggle { display: inline-flex; }

  .sidebar-backdrop:not([hidden]) {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(300px, 88vw);
    z-index: 60;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.2,.8,.2,1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 16px 0 40px rgba(11,63,174,.28);
  }
  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }
  body.nav-lock { overflow: hidden; }

  .top {
    position: sticky; top: 0; z-index: 30;
    padding: 10px 12px 8px;
    background: rgba(242, 246, 243, 0.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    align-items: center;
    gap: 10px;
  }
  .top h1 { font-size: 22px; line-height: 1.2; word-break: break-word; }
  .top-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }
  .assoc-switch { flex: 1 1 140px; min-width: 0; }
  .assoc-switch select { min-width: 0; width: 100%; min-height: 44px; }
  .user-chip { flex: 1 1 120px; min-width: 0; padding: 8px 12px; }
  .user-chip strong { word-break: break-word; }

  .main { padding: 10px 12px 88px; overflow-x: clip; }

  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 24px; }

  .panel { padding: 14px; border-radius: 16px; overflow: hidden; }
  .panel-head { align-items: flex-start; }
  .toolbar { gap: 8px; }
  .toolbar .btn { flex: 1 1 auto; }

  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.span-2 { grid-column: auto; }
  .form-grid input, .form-grid select, .form-grid textarea {
    min-height: 44px; font-size: 16px; /* avoid iOS zoom */
  }

  .table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }
  .table-scroll .table {
    min-width: 640px;
    width: max-content;
    max-width: none;
  }
  .table-scroll .table th,
  .table-scroll .table td { white-space: nowrap; }
  .table-scroll .table td .muted { white-space: normal; max-width: 220px; }

  .login-screen { padding: 20px 14px; align-items: flex-start; padding-top: max(24px, env(safe-area-inset-top)); }
  .login-panel { padding: 24px 18px; border-radius: 20px; }
  .login-brand .brand-name { font-size: 32px; }
  .login-form select, .login-form input {
    min-height: 48px; font-size: 16px;
  }
  .login-links { gap: 10px 14px; }

  .modal-backdrop {
    z-index: 80;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-end;
    padding: 0;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(90dvh, calc(100dvh - 12px)) !important;
    border-radius: 18px 18px 0 0;
    margin: 0 !important;
    flex: 0 1 auto;
  }
  .modal-card-body { padding: 16px 14px 10px; }
  .modal-card h2 { font-size: 20px; }
  .modal-actions {
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    justify-content: stretch;
  }
  .modal-actions .btn { flex: 1 1 auto; }

  .split-tabs button,
  .unit-chip { min-height: 44px; }

  /* Compact „panou mobil”: denser chrome, same features */
  body.layout-compact .stats { grid-template-columns: 1fr 1fr; }
  body.layout-compact .stat { padding: 12px; }
  body.layout-compact .stat .value { font-size: 22px; }
  body.layout-compact .top h1 { font-size: 20px; }
  body.layout-compact .user-chip { padding: 8px 10px; }
  body.layout-compact .user-chip span { display: none; }
  body.layout-compact .compact-toggle {
    background: var(--blue-soft); border-color: transparent; color: var(--blue-deep);
    min-height: 40px; padding: 8px 12px; font-size: 12px;
  }
  body.layout-compact .table-scroll .table { min-width: 560px; font-size: 13px; }
  body.layout-compact .main { padding-bottom: 100px; }
  body.layout-compact .top-actions {
    flex-wrap: nowrap;
  }
  body.layout-compact .compact-toggle {
    flex: 0 0 auto;
    order: 0;
  }
  body.layout-compact .user-chip {
    flex: 1 1 auto;
  }
}

/* —— Phone (~390px): tighter type, keep 2-col stats —— */
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 22px; }
  .top-actions { gap: 8px; }
  .compact-toggle { flex: 0 1 auto; }
  .assoc-switch { flex: 1 1 100%; }
  .user-chip { flex: 1 1 auto; min-width: 0; }
  .login-brand .brand-name { font-size: 28px; }
  .persona-note { font-size: 12px; }
  .table-scroll .table { min-width: 560px; }
  body.layout-compact .top-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
  }
  body.layout-compact .user-chip { grid-column: 1; }
  body.layout-compact .compact-toggle { grid-column: 2; align-self: center; }
  body.layout-compact .assoc-switch { grid-column: 1 / -1; }
}

/* Desktop shell preserved at ≥1024px — menu chrome stays hidden */
