/* Aplicația pentru firme: sobru, neutru, un albastru ca accent.
   Tema: aleasă de utilizator (data-theme pe <html>, din cookie) sau, implicit, cea a sistemului. */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --fg: #1f2933;
  --muted: #616e7c;
  --border: #d9e2ec;
  --accent: #2f6f9f;
  --accent-fg: #ffffff;
  --accent-soft: #e6f0f7;
  --danger: #b42318;
  --warning: #b54708;
  --sidebar-width: 15rem;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111418;
  --surface: #1c2128;
  --fg: #e4e7eb;
  --muted: #9aa5b1;
  --border: #323f4b;
  --accent: #6fb1e0;
  --accent-fg: #0b1a26;
  --accent-soft: #1d3446;
  --danger: #f97066;
  --warning: #fdb022;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --surface: #1c2128;
    --fg: #e4e7eb;
    --muted: #9aa5b1;
    --border: #323f4b;
    --accent: #6fb1e0;
    --accent-fg: #0b1a26;
    --accent-soft: #1d3446;
    --danger: #f97066;
    --warning: #fdb022;
    color-scheme: dark;
  }
}

/* Comutatorul de temă (Automat / Luminos / Întunecat). */
.theme-switch { display: inline-flex; margin: 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.theme-switch button {
  background: none;
  border: 0;
  padding: .2rem .55rem;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.theme-switch button + button { border-left: 1px solid var(--border); }
.theme-switch button[aria-pressed="true"] { background: var(--accent-soft); color: var(--fg); font-weight: 600; }
.auth .theme-switch { margin-top: 1rem; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

/* Structura: antet, meniu lateral, conținut */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .75rem; font-weight: 600; }
.brand img { max-height: 2.25rem; max-width: 10rem; object-fit: contain; }
.user-menu { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.user-menu form { margin: 0; }
.latency { font-size: .8rem; white-space: nowrap; }
.local-folder code { word-break: break-all; user-select: all; }
.small { font-size: .8rem; }
.latency.good { color: var(--success, #1f7a4d); }
.latency.fair { color: #b7791f; }
.latency.slow { color: var(--danger); }
.menu-toggle { display: none; }

/* Căutarea globală din antet (apps/web/search.py) */
.global-search { position: relative; margin: 0 0 0 auto; }
.global-search input { width: 16rem; }
.search-results {
  position: absolute; right: 0; top: calc(100% + .35rem); z-index: 30; width: min(30rem, 92vw);
  max-height: 70vh; overflow-y: auto; padding: .5rem .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
.search-results:empty { display: none; }
.search-group h3 { font-size: .8rem; text-transform: uppercase; color: var(--muted); margin: .5rem 0 .25rem; }
.search-group ul { list-style: none; margin: 0; padding: 0; }
.search-group a { display: block; padding: .3rem .25rem; color: inherit; text-decoration: none; border-radius: 4px; }
.search-group a:hover, .search-group a:focus { background: var(--accent-soft); }
.search-empty { margin: .25rem 0; }
.search-page .search-group h3 { font-size: .9rem; }

/* Versiunea rulată, în subsolul paginii (de menționat când se raportează o problemă) */
.app-version { margin-top: 2.5rem; text-align: right; }

/* Butonul „+ Adaugă” din antet (templates/web/app.html, apps/web/quick_add.py) */
.quick-add { position: relative; }
.quick-add summary {
  list-style: none; cursor: pointer; padding: .35rem .8rem; border-radius: 6px;
  background: var(--accent); color: #fff; font-weight: 600; white-space: nowrap;
}
.quick-add summary::-webkit-details-marker { display: none; }
.quick-add-panel {
  position: absolute; right: 0; top: calc(100% + .35rem); z-index: 20; min-width: 15rem;
  display: grid; grid-template-columns: 1fr 1fr; gap: .1rem; padding: .4rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
.quick-add-panel a {
  display: block; padding: .45rem .6rem; border-radius: 6px; color: var(--fg);
  text-decoration: none; white-space: nowrap;
}
.quick-add-panel a:hover, .quick-add-panel a:focus { background: var(--accent-soft); }
.pick-list { list-style: none; padding: 0; margin: 0; }
.pick-list li + li { border-top: 1px solid var(--border); }
.pick-list a { display: block; padding: .6rem .25rem; color: inherit; text-decoration: none; }
.pick-list a:hover strong { color: var(--accent); }

/* Meniul firmelor (persoanele care lucrează în mai multe firme; apps/core/firms.py) */
.firm-switch { position: relative; }
.firm-switch summary { list-style: none; cursor: pointer; }
.firm-switch summary::-webkit-details-marker { display: none; }
.firm-switch-panel {
  position: absolute; left: 0; top: calc(100% + .35rem); z-index: 20; min-width: 15rem;
  display: grid; gap: .15rem; padding: .6rem; font-weight: 400;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
.firm-switch-panel form { margin: 0; }
.firm-switch-panel button.link { padding: .4rem .2rem; text-align: left; }

.layout { display: flex; min-height: calc(100vh - 3.5rem); }
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  padding: 1rem .75rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar a {
  display: block;
  padding: .45rem .75rem;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
}
.sidebar a:hover { background: var(--accent-soft); }
.sidebar a.active { background: var(--accent); color: var(--accent-fg); }
.content { flex: 1; min-width: 0; padding: 1.5rem; }


h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

/* Carduri și tabele */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  min-width: 0;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border);
         vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.empty { color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem;
         background: var(--accent-soft); color: var(--fg); white-space: nowrap; }
.badge.danger { background: var(--danger); color: #fff; }
.badge.success { background: #1f7a4d; color: #fff; }
.badge.warning { background: var(--warning); color: var(--surface); }
.overdue { color: var(--danger); font-weight: 600; }

/* Formulare și butoane */
button, .button {
  font: inherit;
  padding: .5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.link { background: none; border: 0; padding: 0; color: var(--accent); }
label { display: block; font-weight: 500; margin: .75rem 0 .25rem; }
label.checkbox { display: flex; gap: .5rem; align-items: center; }
label.checkbox input { width: auto; margin: 0; }
input[type=text], input[type=email], input[type=password], .register-filters input[type=search] {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
.errorlist { color: var(--danger); padding-left: 1.1rem; margin: .25rem 0; }
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .5rem .75rem; border-radius: 6px; background: var(--accent-soft); }
.messages li + li { margin-top: .4rem; }
.messages li.warning, .messages li.error { border-left: 4px solid var(--warning); }
.messages li.error { border-left-color: var(--danger); }

/* Paginile de autentificare */
.auth { max-width: 24rem; margin: 10vh auto; }
.auth .card { padding: 1.5rem; }
.auth h1 { text-align: center; }
.verification-code { font-size: 2rem; font-weight: 700; letter-spacing: .3rem; text-align: center; margin: .5rem 0; }
.auth .actions { margin-top: 1.25rem; display: flex; justify-content: space-between;
                 align-items: center; gap: 1rem; }

/* Ajutor pe pagină */
.help {
  margin: 0 0 1.25rem;
  padding: .6rem 1rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
}
.help summary { cursor: pointer; font-weight: 600; }
.help-body { margin-top: .5rem; max-width: 60rem; }
.help-body ul, .help-body ol { margin: .3rem 0 .3rem 1.2rem; padding: 0; }

/* Liste, filtre, formulare pe pagină */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search], .toolbar select, select, textarea, input[type=date], input[type=number] {
  padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--fg); font: inherit;
}
.toolbar input[type=search] { flex: 1; min-width: 14rem; }
input.share { width: 4.5rem; }
.toolbar .spacer { flex: 1; }
.form-grid { display: grid; gap: 0 1.25rem; grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)); }
.form-grid > div { min-width: 0; }
.form-grid select, .form-grid textarea, .form-grid input { width: 100%; }
.helptext { color: var(--muted); font-size: .85rem; }
.client-search input[type=search] { width: 100%; }
.client-search-list { list-style: none; margin: .25rem 0 0; padding: .25rem .5rem;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  max-height: 16rem; overflow-y: auto; }
.client-search-list li { padding: .25rem 0; }
.client-search-list .muted { font-size: .85rem; margin-left: .25rem; }
.form-actions { margin-top: 1.25rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.button.secondary, button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }
.pagination { display: flex; gap: .75rem; align-items: center; margin-top: 1rem; }
.stack > * + * { margin-top: 1rem; }
a.card { color: inherit; text-decoration: none; display: block; }
a.card:hover { border-color: var(--accent); }

/* Ecrane mici (telefon): meniu sub ☰, tabele afișate ca fișe, zone de atins mai mari. */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .topbar { flex-wrap: wrap; padding: .5rem 1rem; gap: .5rem; }
  .brand { flex: 1; min-width: 0; }
  .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-toggle {
    display: inline-block;
    font-size: 1.4rem;
    line-height: 1;
    padding: .45rem .7rem;
    background: transparent;
    color: var(--fg);
    border-color: var(--border);
  }
  .user-menu { display: none; width: 100%; flex-wrap: wrap; padding: .5rem 0 .25rem;
               border-top: 1px solid var(--border); }
  .menu-open .user-menu { display: flex; }
  .quick-add { margin-left: 0; }
  .global-search { width: 100%; margin: 0; order: 3; }
  .global-search input { width: 100%; }
  .search-results { left: 0; right: 0; width: auto; }
  .quick-add-panel { position: fixed; left: .5rem; right: .5rem; top: 3.25rem; min-width: 0; }

  .layout { flex-direction: column; min-height: 0; }
  .sidebar { display: none; width: auto; border-right: 0; border-bottom: 1px solid var(--border);
             padding: .5rem; }
  .menu-open .sidebar { display: block; }
  .sidebar a { padding: .7rem .9rem; }
  .content { padding: 1rem; }
  .card { padding: .85rem 1rem; }

  /* Tabelele devin fișe: fiecare rând e un bloc, cu numele coloanei lângă valoare. */
  .table-wrap { overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { padding: .5rem 0; border-bottom: 1px solid var(--border); }
  .table-wrap tr:last-child { border-bottom: 0; }
  .table-wrap td { display: flex; gap: .75rem; padding: .15rem 0; border: 0; overflow-wrap: anywhere; }
  .table-wrap td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 7.5rem;
    color: var(--muted);
    font-size: .85rem;
  }
  .table-wrap td:empty { display: none; }

  /* Zone de atins: minimum ~44px; 16px în câmpuri, altfel iPhone mărește pagina la tastare. */
  button, .button { padding: .65rem 1.1rem; }
  button.link { padding: .35rem 0; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; min-height: 2.75rem; }
  input[type=checkbox], input[type=radio] { width: 1.25rem; height: 1.25rem; }
  textarea { min-height: 5rem; }
  .toolbar input[type=search] { min-width: 0; flex-basis: 100%; }
  .form-actions > * { flex: 1 1 auto; text-align: center; }
  dl.details { grid-template-columns: 1fr; gap: 0; }
  dl.details dt { margin-top: .6rem; font-size: .85rem; }
  .auth { margin: 1.5rem auto; padding: 0 1rem; }
  .theme-switch button { padding: .45rem .7rem; }
}

/* Panoul documentațiilor (kanban) */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(12rem, 1fr); gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.board-column { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem; min-height: 6rem; }
.board-column h2 { font-size: 1rem; margin: 0 0 .5rem; display: flex; justify-content: space-between; align-items: center; }
.board-card { display: flex; flex-direction: column; gap: .15rem; padding: .55rem .6rem; margin-bottom: .5rem; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 6px; background: var(--bg); color: var(--fg); text-decoration: none; font-size: .9rem; }
.board-card:hover { border-color: var(--accent); }
.board-card.overdue { border-left-color: var(--danger); }
.board-card-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.board-card-foot { font-size: .8rem; margin-top: .2rem; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-size: .7rem; font-weight: 600; }
.danger-text { color: var(--danger); font-weight: 600; }
.board-filters { margin: 0; }
@media (max-width: 700px) { .board { grid-auto-flow: row; grid-auto-columns: auto; } }

/* Calendarul */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.calendar-head { background: var(--surface); padding: .35rem; font-weight: 600; font-size: .85rem; text-align: center; }
.calendar-day { background: var(--surface); min-height: 6rem; padding: .25rem; display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.calendar-day.other { background: var(--bg); color: var(--muted); }
.calendar-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.calendar-date { font-size: .8rem; align-self: flex-end; }
.calendar-day.holiday { background: var(--accent-soft); }
.calendar-holiday { font-size: .72rem; font-weight: 600; color: var(--muted); line-height: 1.2; }
.event-key.event-holiday { background: var(--accent-soft); color: var(--fg); }
.calendar-title { font-size: 1.1rem; text-transform: capitalize; min-width: 10rem; text-align: center; }
.event { display: block; font-size: .75rem; padding: .1rem .3rem; border-radius: 4px; color: #fff; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-key { display: inline-block; font-size: .75rem; padding: .05rem .4rem; border-radius: 4px; color: #fff; }
.event-documentation { background: #2f6f9f; }
.event-project { background: #1f7a4d; }
.event-ocpi { background: var(--danger); }
.event-task { background: #616e7c; }
.event-task_done { background: #9aa5b1; text-decoration: line-through; }
.event-absence { background: #b7791f; }
.event-visit { background: #6b46c1; }
@media (max-width: 700px) { .calendar-day { min-height: 4rem; } .event { font-size: .65rem; } }

/* Registrul de lucrări */
.register td.num, .register th.num { text-align: right; white-space: nowrap; }
.overdue-row td { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.register-filters { margin-bottom: 1rem; }
@media print {
  .sidebar, .topbar, .no-print, .help, .menu-toggle, .messages { display: none !important; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .register { font-size: 9pt; }
  a { color: inherit; text-decoration: none; }
}

/* Sinteza biroului (panou) */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; gap: .2rem; padding: .7rem .8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--fg); text-decoration: none; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.5rem; }
.stat small { font-size: .8rem; font-weight: normal; }
.stat:hover { border-color: var(--accent); }
.stat-danger { border-color: var(--danger); }
.stat-danger strong { color: var(--danger); }
.stat-warning { border-color: var(--warning); }
.status-counts ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
