/* ==========================================================================
   Docy v2 — foaia de stil a aplicației
   Structură: reset → shell → sidebar → topbar → login → tipografie pagină →
   panouri → tabele → formulare → butoane → badge-uri → KPI/bare → kanban →
   modale → toast → utilitare → print
   ========================================================================== */

/* ---------- Reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; color: inherit; }

::selection { background: var(--accent-soft); }

/* Bare de derulare discrete, în ton cu tema */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- Shell ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#view {
  flex: 1;
  padding: var(--sp-5);
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--side-bg);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--side-border);
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  background: var(--side-bg-2);
  border: 1px solid var(--side-border);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.brand-name { color: #fff; font-size: 15px; font-weight: 650; letter-spacing: 0.01em; }
.brand-sub { font-size: 10.5px; color: var(--side-text); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 1px; }

.nav { flex: 1; overflow-y: auto; padding: 10px 0 16px; }

.nav-label {
  padding: 16px 18px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #6d7f96;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 18px;
  color: var(--side-text);
  border-left: 2px solid transparent;
  font-size: 13px;
}

.nav-item .icon { color: #7d8fa6; }
.nav-item:hover .icon { color: var(--side-text-active); }
.nav-item.active .icon { color: #d8a03d; }

.icon { display: inline-flex; flex: none; }
.icon svg { display: block; }

.nav-item:hover { background: var(--side-hover); color: var(--side-text-active); text-decoration: none; }

.nav-item.active {
  background: var(--side-hover);
  color: var(--side-text-active);
  border-left-color: #d8a03d;
  font-weight: 600;
}

.nav-count {
  font-size: 10.5px;
  background: var(--side-bg-2);
  border: 1px solid var(--side-border);
  border-radius: 8px;
  padding: 0 6px;
  color: var(--side-text);
  font-variant-numeric: tabular-nums;
}

.sidebar-footer {
  border-top: 1px solid var(--side-border);
  padding: 12px 18px;
  font-size: 12px;
}

.sidebar-footer .org { color: #fff; font-weight: 600; }
.sidebar-footer .who { color: var(--side-text); margin-top: 2px; }

/* ---------- Topbar ---------- */

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 16px; font-weight: 650; }

.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.user-chip .name { font-weight: 600; font-size: 12.5px; }
.user-chip .role { color: var(--text-2); font-size: 11px; }

/* ---------- Login ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--side-bg-2);
  padding: var(--sp-4);
}

.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: var(--sp-6);
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand .brand-mark { background: var(--side-bg); width: 36px; height: 36px; font-size: 15px; }
.login-title { font-size: 19px; font-weight: 700; }
.login-sub { color: var(--text-2); font-size: 12.5px; margin-bottom: var(--sp-5); }

.login-demo {
  margin-top: var(--sp-5);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
}

.login-demo table { border-collapse: collapse; }
.login-demo td { padding: 1px 10px 1px 0; font-family: var(--mono); font-size: 11.5px; }

/* ---------- Cap de pagină ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.page-head .crumbs { color: var(--text-3); font-size: 12px; margin-bottom: 2px; }
.page-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.page-head .sub { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.page-actions { display: flex; gap: var(--sp-2); flex: none; }

/* ---------- Panouri ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  margin-bottom: var(--sp-5);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}

.panel-head h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
}

.panel-body { padding: var(--sp-4); }
.panel-body.p0 { padding: 0; }

/* ---------- Tabele ---------- */

.table-wrap { overflow-x: auto; }

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tbl th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  white-space: nowrap;
  font-weight: 700;
}

.tbl td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--surface-3);
  vertical-align: middle;
}

.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr.click:hover { background: var(--accent-soft); cursor: pointer; }

.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .strong { font-weight: 650; }
.tbl .code { font-family: var(--mono); font-size: 12px; color: var(--text-2); white-space: nowrap; }
.tbl .muted { color: var(--text-3); }
.tbl .actions { text-align: right; white-space: nowrap; }

tfoot.tbl-total td {
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
  background: var(--surface-2);
  font-weight: 700;
}

/* ---------- Formulare ---------- */

.field { margin-bottom: var(--sp-4); }

.field > label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 4px;
}

.field .req { color: var(--danger); }

.field .hint { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], select, textarea {
  width: 100%;
  padding: 6px 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

input.inv, textarea.inv { border-color: var(--danger); background: #fffafa; }

textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }

select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23566070'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 26px; }

.ferr { color: var(--danger); font-size: 11.5px; margin-top: 3px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--sp-4); }
.form-grid .span2 { grid-column: span 2; }

/* ---------- Butoane ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }

.btn-danger { background: var(--surface); border-color: var(--danger-border); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

.btn-ok { background: var(--surface); border-color: var(--ok-border); color: var(--ok); }
.btn-ok:hover { background: var(--ok-soft); }

.btn-sm { height: 24px; padding: 0 9px; font-size: 11.5px; font-weight: 600; }

.btn-block { width: 100%; height: 36px; font-size: 13.5px; }

.btn-icon { padding: 0 8px; }

/* ---------- Badge-uri de status ---------- */

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: var(--radius);
  border: 1px solid;
  white-space: nowrap;
}

.b-draft    { color: var(--text-2); background: var(--surface-3); border-color: var(--border-strong); }
.b-pending  { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.b-approved { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-border); }
.b-rejected { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.b-planned  { color: var(--text-2); background: var(--surface-3); border-color: var(--border-strong); }
.b-active   { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-border); }
.b-hold     { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.b-completed{ color: var(--ok); background: var(--ok-soft); border-color: var(--ok-border); }
.b-cancelled{ color: var(--text-3); background: var(--surface-3); border-color: var(--border-strong); }
.b-info     { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-border); }
.b-muted    { color: var(--text-3); background: var(--surface-2); border-color: var(--border); }

/* ---------- KPI și bare de execuție ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 12px var(--sp-4) 10px;
}

.kpi .label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}

.kpi .value { font-size: 21px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi .sub { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); align-items: start; }

.exec-row { padding: 9px 0; border-bottom: 1px solid var(--surface-3); }
.exec-row:last-child { border-bottom: none; }

.exec-top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); margin-bottom: 4px; }
.exec-top .name { font-weight: 600; font-size: 12.5px; }
.exec-top .name .code { font-weight: 400; }
.exec-top .pct { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }

.bar { height: 8px; background: var(--surface-3); border-radius: var(--radius); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.warn { background: var(--warn-bar); }
.bar > i.ok { background: var(--ok); }

.legend { display: flex; gap: var(--sp-4); font-size: 11px; color: var(--text-2); margin-top: 10px; flex-wrap: wrap; }
.legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: var(--radius); margin-right: 5px; vertical-align: baseline; }

/* ---------- Kanban ---------- */

.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: var(--sp-3);
  align-items: start;
}

.kcol {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 220px;
}

.kcol.over { outline: 2px dashed var(--accent); outline-offset: -2px; }

.kcol-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.kcol-head .t { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); }
.kcol-head .n { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.kcol-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; }

.kcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 9px 10px;
  cursor: grab;
}

.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: 0.45; }
.kcard .code { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }
.kcard .name { font-weight: 600; font-size: 12.5px; margin: 2px 0 6px; line-height: 1.35; }
.kcard .money { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.kcard .money b { color: var(--text); }
.kcard .meta { font-size: 10.5px; color: var(--text-3); margin-top: 4px; }

/* ---------- Modale ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 23, 36, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: var(--sp-4);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  width: 520px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal.wide { width: 780px; }
.modal.narrow { width: 400px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal-head h3 { font-size: 13.5px; font-weight: 700; }

.modal-x {
  border: none;
  background: none;
  font-size: 17px;
  line-height: 1;
  color: var(--text-2);
  cursor: pointer;
  padding: 2px 6px;
}

.modal-body { padding: var(--sp-4) var(--sp-4) 0; overflow-y: auto; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- Toast ---------- */

.toast-wrap {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 10px 14px;
  min-width: 260px;
  max-width: 380px;
  font-size: 12.5px;
}

.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast b { display: block; margin-bottom: 1px; }

/* ---------- Alerte și stări ---------- */

.alert {
  border: 1px solid;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: var(--sp-4);
}

.alert-info { background: var(--info-soft); border-color: var(--info-border); color: var(--text); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn-border); }

.empty { text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--text-2); }
.empty .t { font-weight: 650; color: var(--text); margin-bottom: 2px; }

.loading { display: grid; place-items: center; padding: var(--sp-6); color: var(--text-3); font-size: 12.5px; gap: 10px; }

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bară de filtre / paginare ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-4);
}

.toolbar .grow { flex: 1; }
.toolbar select, .toolbar input { width: auto; min-width: 130px; height: 30px; padding: 4px 26px 4px 8px; font-size: 12.5px; }
.toolbar input { padding: 4px 8px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-2);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------- Listă de definiții (detalii) ---------- */

.kv { display: grid; grid-template-columns: 150px 1fr; row-gap: 7px; column-gap: var(--sp-3); font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

/* ---------- Cronologie (istoric / audit) ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--surface-3); font-size: 12.5px; }
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--text-3); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; width: 118px; flex: none; padding-top: 1px; }
.timeline .who { font-weight: 650; }

/* ---------- Document preview ---------- */

.doc-preview {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: var(--sp-5);
  max-height: 60vh;
  overflow: auto;
}

/* ---------- Utilitare ---------- */

.mono { font-family: var(--mono); }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.stack > * + * { margin-top: var(--sp-3); }

/* ---------- Print (previzualizare contract) ---------- */

@media print {
  .sidebar, .topbar, .page-actions, .no-print { display: none !important; }
  #view { padding: 0; max-width: none; }
  body { background: #fff; }
  .doc-preview { border: none; max-height: none; padding: 0; font-size: 11.5pt; }
}

/* ---------- Ecran îngust ---------- */

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: repeat(2, 1fr); }
}
