:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fbff;
  --text: #14213d;
  --muted: #687487;
  --primary: #1167e8;
  --primary-dark: #0a4fb7;
  --green: #17a673;
  --line: #dbe4f0;
  --danger: #c62828;
  --warning: #b76e00;
  --shadow: 0 16px 40px rgba(20,33,61,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Segoe UI, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.small-top { margin-top: 14px; }
.center { justify-content: center; }

.app-shell { display: grid; grid-template-columns: 286px 1fr; min-height: 100vh; }
.sidebar { background: #071933; color: white; padding: 24px 18px; display: flex; flex-direction: column; gap: 22px; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row-sidebar { align-items: center; }
.brand-row-auth { margin-bottom: 6px; }
.brand-logo { display: block; object-fit: contain; filter: drop-shadow(0 8px 18px rgba(17,103,232,.16)); }
.brand-logo-auth { width: 88px; height: 88px; }
.brand-logo-sidebar { width: 76px; height: 76px; border-radius: 18px; background: rgba(255,255,255,.06); padding: 8px; }
.brand-title { font-size: 23px; font-weight: 900; letter-spacing: .05em; line-height: 1.05; }
.brand-title.dark { color: var(--text); }
.brand-subtitle { font-size: 12px; color: #9db4d2; letter-spacing: .08em; }
.brand-auth-subtitle { letter-spacing: .08em; font-size: 12px; }
.upper { text-transform: uppercase; }
nav { display: grid; gap: 7px; }
.nav-link { text-decoration: none; color: #c8d8ee; padding: 12px 14px; border-radius: 14px; font-weight: 650; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.12); color: white; }
.sidebar-note { margin-top: auto; padding: 16px; border-radius: 18px; background: rgba(255,255,255,.09); color: #e4eefc; line-height: 1.45; }
.sidebar-note p { margin-bottom: 0; font-size: 13px; color: #c8d8ee; }

.main { padding: 26px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 30px; }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
select, input, textarea { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; min-height: 42px; color: var(--text); width: 100%; }
textarea { min-height: 90px; resize: vertical; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: #2b3b55; }

.btn { border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 750; cursor: pointer; min-height: 42px; }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #eaf2ff; color: var(--primary); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.danger { background: #ffe9e9; color: var(--danger); }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: #eef4fb; font-size: 20px; cursor: pointer; }

.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin: 0 0 12px; }
.stat .label { color: var(--muted); font-weight: 700; font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 850; margin-top: 8px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)); gap: 12px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.three { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
.full { grid-column: 1 / -1; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 18px; overflow: hidden; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid #edf2f7; vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #f8fbff; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 750; background: #eaf2ff; color: var(--primary); }
.badge.green { background: #e7fff5; color: var(--green); }
.badge.warn { background: #fff5de; color: var(--warning); }
.badge.red { background: #ffe9e9; color: var(--danger); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .btn { padding: 7px 10px; min-height: 34px; font-size: 12px; }

.alert { padding: 14px 16px; border-radius: 16px; margin-bottom: 14px; background: #eaf2ff; border: 1px solid #cfe0ff; color: #0a4fb7; }
.alert.error { background: #fff0f0; border-color: #ffd0d0; color: var(--danger); }
.alert.success { background: #e7fff5; border-color: #bdf4df; color: #0b7650; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top left, #dff5ff, transparent 30%), radial-gradient(circle at bottom right, #d9ffef, transparent 32%), var(--bg); }
.auth-card { width: min(480px, 100%); background: #fff; padding: 28px; border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: 6px; }
summary { cursor: pointer; margin-top: 16px; color: var(--primary); font-weight: 750; }

.modal { position: fixed; inset: 0; background: rgba(7,25,51,.55); display: grid; place-items: center; padding: 18px; z-index: 20; }
.modal-card { width: min(980px, 100%); max-height: 88vh; overflow: auto; background: #fff; border-radius: 22px; padding: 18px; box-shadow: 0 25px 70px rgba(0,0,0,.25); }

.modal-card--nir {
  width: min(1480px, 96vw);
  max-height: 94vh;
  padding: 20px 20px 16px;
}
.modal-card--nir .modal-body {
  overflow: auto;
}
.modal-card--nir .nir-table-wrap {
  max-height: calc(94vh - 290px);
  overflow: auto;
}
.modal-card--nir .row.between {
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
@media (max-width: 1200px) {
  .modal-card--nir { width: min(1280px, 98vw); max-height: 95vh; }
  .modal-card--nir .nir-table-wrap { max-height: calc(95vh - 280px); }
}
@media (max-width: 820px) {
  .modal-card--nir { width: 100%; padding: 14px; border-radius: 18px; }
  .modal-card--nir .nir-table-wrap { max-height: calc(95vh - 260px); }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.modal-header h2 { margin: 0; }
pre { white-space: pre-wrap; word-break: break-word; background: #071933; color: #e4eefc; border-radius: 16px; padding: 16px; overflow: auto; }

.line-editor { border: 1px dashed var(--line); padding: 12px; border-radius: 16px; background: var(--panel-soft); margin-bottom: 10px; }
.total-box { background: #071933; color: white; border-radius: 18px; padding: 16px; display: grid; gap: 8px; min-width: 260px; }
.total-box div { display: flex; justify-content: space-between; gap: 14px; }
.total-box .grand { font-size: 22px; font-weight: 850; border-top: 1px solid rgba(255,255,255,.2); padding-top: 10px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  nav { grid-template-columns: repeat(2, 1fr); }
  .grid.cards { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; }
}
@media (max-width: 640px) {
  .main { padding: 16px; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .grid.cards { grid-template-columns: 1fr; }
  .top-actions { width: 100%; }
  .top-actions select, .top-actions .btn { flex: 1; }
}
.kv { display: grid; gap: 10px; margin: 12px 0; }
.kv div { background: #f8fbff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.kv span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.kv strong, code { word-break: break-all; }
code { background: #eef4fb; border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; }
.grid.two { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
.notice { background:#fff7e6; border:1px solid #ffe0a6; color:#7a4b00; padding:10px 12px; border-radius:14px; }
@media (max-width: 640px) { .grid.two { grid-template-columns: 1fr; } }


/* NIR / document furnizor */
.nir-head.pretty { display:grid; grid-template-columns: 1.5fr 1fr 1fr; gap:12px; margin-bottom:14px; }
.nir-head.pretty > div { border:1px solid var(--line); border-radius:16px; background:#f8fbff; padding:12px; display:grid; gap:4px; }
.nir-head.pretty strong { font-size:16px; }
.nir-table-wrap { border:1px solid var(--line); border-radius:18px; background:white; }
.nir-table th { background:#071933; color:#fff; }
.nir-table td { vertical-align:middle; }
.nir-table .nir-sale-price { min-width:130px; }
.nir-table select { min-width:190px; }
.nir-row:nth-child(even) td { background:#fbfdff; }
@media (max-width: 900px) { .nir-head.pretty { grid-template-columns: 1fr; } }

/* Dialog NIR actualizat */
.modal-body { color: var(--text); background: #fff; }
.modal-body.html-body { white-space: normal; word-break: normal; }
.modal-body pre { white-space: pre-wrap; word-break: break-word; background: #071933; color: #e4eefc; border-radius: 16px; padding: 16px; overflow: auto; }
.nir-head.pretty > div { background:#ffffff; color: var(--text); }
.nir-head.pretty strong, .nir-table td, .nir-table td strong { color: var(--text); }
.nir-table td .muted, .nir-head .muted { color:#4b5a6c; }
.nir-table td { background:#fff; }
.nir-row:nth-child(even) td { background:#f8fbff; }
.nir-table select, .nir-table input { color: var(--text); background:#fff; }


.nir-table { min-width: 1120px; }
.nir-table th, .nir-table td { padding: 12px 10px; }
.nir-table th { white-space: nowrap; }
.nir-table td.num { white-space: nowrap; }
.nir-table .small { font-size: 11px; }

/* Facturare reală */
.invoice-form-real .line-editor { background: #fff; border: 1px solid var(--line); }
.invoice-form-real .line-editor select,
.invoice-form-real .line-editor input { min-height: 42px; }
.invoice-form-real .total-box { background: #071933; }
.invoice-line-editor .line-description { font-weight: 700; }

.btn.danger-soft { background:#fff0f0; color:#b42318; border-color:#ffd0d0; font-weight:800; }
.btn.danger-soft:hover { background:#ffe4e4; }
.badge.red { background:#ffe7e7; color:#c62828; }
.row.right { justify-content:flex-end; }

.feature-grid { display:grid; gap:8px; font-size:13px; }
.check { display:flex; align-items:center; gap:8px; cursor:pointer; }
.check input { width:auto; }
.admin-nav { border:1px solid rgba(255,255,255,.16); }

/* Admin Global - contabili */
.modal-card.wide-modal { width: min(1320px, 98vw); max-height: 94vh; }
.feature-grid.compact { grid-template-columns: repeat(2, minmax(90px, 1fr)); gap: 6px 12px; }
.admin-role { min-width: 140px; }


.sidebar .brand-title { color: #fff; }
.sidebar .brand-subtitle { color: #a9c1df; }
@media (max-width: 640px) { .brand-logo-auth { width: 76px; height: 76px; } .brand-logo-sidebar { width: 64px; height: 64px; } }


/* CONTABSMART - logo only in sidebar */
.logo-only-sidebar {
  justify-content: center;
  align-items: center;
  padding: 6px 0 14px;
  margin-bottom: 8px;
}
.brand-logo-sidebar-only {
  width: 142px !important;
  height: 142px !important;
  object-fit: contain;
  border-radius: 26px;
  background: rgba(255,255,255,.98);
  padding: 16px;
  box-shadow: 0 16px 34px rgba(0,0,0,.22);
  filter: none;
}
.logo-only-sidebar .brand-title,
.logo-only-sidebar .brand-subtitle {
  display: none !important;
}
@media (max-width: 980px) {
  .logo-only-sidebar { justify-content: flex-start; padding-bottom: 8px; }
  .brand-logo-sidebar-only { width: 104px !important; height: 104px !important; padding: 12px; }
}

/* Paginare tabele */
.table-pager { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 2px 0; flex-wrap:wrap; }
.table-pager .btn[disabled] { opacity:.45; cursor:not-allowed; }
.ok { color: var(--green); }
.danger { color: var(--danger); }


/* Dashboard structurat CONTABSMART */
.dashboard-status-row { margin-bottom: 12px; }
.dashboard-kpis { margin-bottom: 16px; }
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.dashboard-panel { min-height: 330px; display: flex; flex-direction: column; }
.dashboard-panel-head { margin-bottom: 8px; align-items: center; }
.dashboard-panel-head h2 { margin: 0; }
.dashboard-panel .table-wrap { flex: 1; }
.dashboard-table { font-size: 13px; table-layout: fixed; }
.dashboard-table th, .dashboard-table td { padding: 10px 8px; }
.dashboard-table th:nth-child(1), .dashboard-table td:nth-child(1) { width: 86px; }
.dashboard-table th:last-child, .dashboard-table td:last-child { width: 132px; }
.dashboard-actions { gap: 5px; }
.dashboard-actions .btn { padding: 6px 8px; min-height: 30px; font-size: 11px; }
.clip-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.dashboard-table .clip-cell { display: table-cell; word-break: break-word; }
@media (max-width: 1280px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-panel { min-height: auto; }
}
@media (max-width: 760px) {
  .dashboard-table { min-width: 760px; }
  .dashboard-status-row { align-items: flex-start; }
}

/* OPME generator */
.modal-card--opme { width: min(1540px, 98vw); max-height: 95vh; }
.modal-card--opme .modal-body { overflow: auto; }
.form-grid.four { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.opme-table-wrap { max-height: calc(95vh - 330px); overflow: auto; border: 1px solid var(--line); border-radius: 18px; }
.opme-table { min-width: 1320px; }
.opme-table th { background: #071933; color: #fff; white-space: nowrap; }
.opme-table td { vertical-align: top; background: #fff; }
.opme-row:nth-child(even) td { background: #f8fbff; }
.opme-table input, .opme-table select { min-height: 38px; }
.opme-nr { width: 68px; text-align: center; font-weight: 800; }
.opme-payer-iban { min-width: 210px; margin-bottom: 6px; }
.opme-payer-iban-free { min-width: 210px; }
.opme-beneficiary-name { min-width: 230px; }
.opme-beneficiary-cif { min-width: 120px; }
.opme-beneficiary-iban { min-width: 230px; }
.opme-amount { width: 120px; }
.opme-representing { min-width: 240px; }
.declaration-generator .kv { margin: 14px 0; }
@media (max-width: 980px) {
  .form-grid.four { grid-template-columns: 1fr; }
  .modal-card--opme { width: 100%; padding: 14px; border-radius: 18px; }
}


.sidebar-build {
  margin: auto 18px 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.56);
  font-size: 11px;
  text-align: center;
}


.actions { vertical-align: top; }
.opme-action-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 240px; }
.opme-status-note { display: flex; flex-direction: column; gap: 6px; max-width: 320px; }
.opme-status-note .muted { line-height: 1.35; }


.btn.small { padding: 6px 10px; min-height: 30px; font-size: 12px; border-radius: 10px; }
.declarations-table table td { vertical-align: top; }
.declarations-table table th, .declarations-table table td { padding-top: 10px; padding-bottom: 10px; }
.decl-main { display: flex; flex-direction: column; gap: 4px; }
.declaration-meta { line-height: 1.25; }
.portal-chip { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; background: #f4f7fb; color: var(--primary); font-weight: 700; font-size: 12px; }
.status-stack.compact, .file-stack.compact { display: flex; flex-direction: column; gap: 6px; }
.status-detail { line-height: 1.35; max-width: 320px; }
.opme-row td { padding-top: 8px; padding-bottom: 8px; }
.opme-row.is-working { background: linear-gradient(90deg, rgba(255,245,222,0.45), rgba(255,255,255,0)); }
.opme-row.is-complete { background: linear-gradient(90deg, rgba(231,255,245,0.55), rgba(255,255,255,0)); }
.opme-row.is-error { background: linear-gradient(90deg, rgba(255,233,233,0.55), rgba(255,255,255,0)); }
.opme-action-stack { gap: 6px; min-width: 250px; }
.actions-opme { min-width: 260px; }
.opme-status-note { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: #fbfcfe; }
.opme-status-note.processing { background: #fffaf0; border-color: #f6ddb0; }
.opme-status-note.success { background: #f2fff8; border-color: #c9f1db; }
.opme-status-note.danger { background: #fff4f4; border-color: #ffd4d4; }
.status-inline { display: flex; align-items: center; gap: 6px; }
.spinner { width: 12px; height: 12px; border: 2px solid rgba(180,120,0,0.25); border-top-color: var(--warning); border-radius: 50%; display: inline-block; animation: spin 0.9s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@media (max-width: 980px) {
  .status-detail { max-width: 220px; }
  .actions-opme, .opme-action-stack { min-width: 220px; }
}
