:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #172033;
  --muted: #6b7280;
  --border: #d9dee8;
  --primary: #2058d6;
  --primary-dark: #1641a4;
  --danger: #d93025;
  --warning: #b7791f;
  --success: #0f766e;
  --purple: #6d28d9;
  --shadow: 0 16px 40px rgba(20, 35, 70, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Tahoma, Arial, "Segoe UI", sans-serif;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }

/* ══════════════════════════════════════════
   LOGIN SCREEN
══════════════════════════════════════════ */

.login-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f1e3d 0%, #1e3a6e 50%, #2058d6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 28px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 40px 80px rgba(0,0,0,0.3);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand h1 {
  margin: 14px 0 6px;
  font-size: 26px;
  color: var(--text);
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.brand-icon.large {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  display: inline-grid;
  place-items: center;
  background: var(--primary);
  font-size: 36px;
  font-weight: 800;
  color: white;
  margin: 0 auto;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-error {
  display: none;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}

.login-error.visible { display: block; }

.login-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border-radius: 14px;
  margin-top: 4px;
}

.login-hint {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.login-hint p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
  background: var(--bg);
}

.hint-row code {
  font-family: monospace;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* ══════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════ */

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #101827;
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--primary);
  font-size: 24px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}

.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 3px 0 0; color: #bac5d6; font-size: 12px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  border: 0;
  background: transparent;
  color: #dbe4f0;
  text-align: right;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-footer {
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.12);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.sidebar-user { flex: 1; min-width: 0; }

.sidebar-user-name {
  font-size: 14px;
  color: #fff;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ══════════════════════════════════════════
   ROLE BADGES
══════════════════════════════════════════ */

.role-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,0.15);
  color: #dbe4f0;
}

.role-badge.role-management {
  background: rgba(109, 40, 217, 0.25);
  color: #c4b5fd;
}

.role-badge.role-accounting {
  background: rgba(32, 88, 214, 0.25);
  color: #93c5fd;
}

.role-badge.role-viewer {
  background: rgba(107, 114, 128, 0.25);
  color: #d1d5db;
}

/* ══════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════ */

.main {
  padding: 26px;
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.topbar h2 { margin: 0 0 6px; font-size: 28px; }
.topbar p { margin: 0; color: var(--muted); }

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ══════════════════════════════════════════
   NOTIFICATION BELL
══════════════════════════════════════════ */

.notif-wrapper { position: relative; }

.icon-btn {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: var(--text);
  transition: 0.15s;
}

.icon-btn:hover { background: var(--surface-2); }

.notif-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
}

.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  z-index: 200;
  display: none;
  overflow: hidden;
}

.notif-panel.open { display: block; }

.notif-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.notif-list { max-height: 340px; overflow-y: auto; }

.notif-item {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: 0.15s;
  align-items: flex-start;
}

.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--bg); }
.notif-item.read .notif-dot { background: transparent; border: 2px solid var(--border); }
.notif-item.read { opacity: 0.7; }

.notif-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
  background: var(--primary);
}

.notif-critical .notif-dot { background: var(--danger); }
.notif-warning .notif-dot { background: #f59e0b; }
.notif-info .notif-dot { background: var(--primary); }

.notif-content strong { display: block; font-size: 13px; margin-bottom: 3px; }
.notif-content p { margin: 0 0 4px; font-size: 12px; color: var(--muted); }
.notif-content small { font-size: 11px; color: var(--muted); }

.notif-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */

button {
  border: 0;
  cursor: pointer;
  border-radius: 12px;
  padding: 11px 16px;
}

.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-dark); }

.secondary { background: var(--surface-2); color: var(--text); }

.ghost {
  background: transparent;
  color: inherit;
  border: 1px solid var(--border);
}

.small { padding: 6px 10px; font-size: 12px; }

.danger-btn { background: #fee2e2; color: #991b1b; }

/* ══════════════════════════════════════════
   SCREENS
══════════════════════════════════════════ */

.screen { display: none; }
.screen.active { display: block; }

/* ══════════════════════════════════════════
   ALERTS & METRICS
══════════════════════════════════════════ */

.alert {
  padding: 15px 18px;
  border-radius: 16px;
  margin-bottom: 18px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #7c2d12;
}

.alert.critical {
  background: #fef2f2;
  border-color: #fecaca;
  color: #7f1d1d;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.metric-card span { color: var(--muted); display: block; margin-bottom: 10px; }
.metric-card strong { display: block; font-size: 30px; margin-bottom: 6px; }
.metric-card small { color: var(--muted); }
.metric-card.warning { border-color: #f6d365; }
.metric-card.danger { border-color: #fca5a5; }

/* ══════════════════════════════════════════
   LAYOUT HELPERS
══════════════════════════════════════════ */

.two-col {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel h3 { margin: 0 0 18px; font-size: 19px; }

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-header h3 { margin: 0; }

.empty-state {
  color: var(--muted);
  margin: 0;
  padding: 24px;
  text-align: center;
}

/* ══════════════════════════════════════════
   TABLES
══════════════════════════════════════════ */

table { width: 100%; border-collapse: collapse; overflow: hidden; }

th, td {
  text-align: right;
  border-bottom: 1px solid var(--border);
  padding: 13px 10px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  background: #fafbfe;
}

/* ══════════════════════════════════════════
   TAGS
══════════════════════════════════════════ */

.tag {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
}

.tag.amber { background: #fef3c7; color: #92400e; }
.tag.green { background: #ccfbf1; color: #115e59; }
.tag.blue  { background: #dbeafe; color: #1e40af; }
.tag.red   { background: #fee2e2; color: #991b1b; }
.tag.purple { background: #ede9fe; color: var(--purple); }

/* ══════════════════════════════════════════
   CASHFLOW
══════════════════════════════════════════ */

.cashflow { display: grid; gap: 14px; }

.cashflow div {
  padding: 16px;
  border-radius: 16px;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.cashflow span { color: var(--muted); }
.cashflow strong { font-size: 18px; }
.cashflow .net { background: #ecfdf5; color: #065f46; }

/* ══════════════════════════════════════════
   STEPPER
══════════════════════════════════════════ */

.stepper {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  overflow-x: auto;
}

.step {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

.step.active {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

/* ══════════════════════════════════════════
   FORM
══════════════════════════════════════════ */

.form-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.form-grid.processing { opacity: 0.5; pointer-events: none; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: white;
  border-radius: 12px;
  padding: 12px 13px;
  color: var(--text);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(32, 88, 214, 0.12);
}

input.ocr-filled {
  border-color: #86efac;
  background: #f0fdf4;
}

textarea { min-height: 92px; resize: vertical; }

.wide { grid-column: 1 / -1; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ══════════════════════════════════════════
   UPLOAD & OCR
══════════════════════════════════════════ */

.upload-box {
  border: 2px dashed var(--border);
  border-radius: 18px;
  padding: 14px;
  display: grid;
  gap: 12px;
  min-height: 180px;
  transition: 0.2s;
}

.upload-box:has(input:focus) { border-color: var(--primary); }

.upload-box input { display: none; }

.upload-box label {
  text-align: center;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #f8fafc;
  padding: 22px;
  color: var(--text);
  cursor: pointer;
  gap: 6px;
  transition: 0.2s;
}

.upload-box label:hover { background: #eff6ff; border-color: var(--primary); }
.upload-box small { color: var(--muted); margin-top: 2px; }

.upload-box img {
  display: none;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* OCR Box */
.ocr-box { margin-top: 18px; }
.ocr-box h4 { margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }

.ocr-badge {
  font-size: 10px;
  font-weight: 700;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.ocr-placeholder {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: #fafbfe;
}

.ocr-placeholder p { margin: 0; line-height: 1.8; }

/* OCR processing spinner */
.ocr-processing {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}

.ocr-processing p { margin: 12px 0 4px; font-weight: 600; color: var(--text); }
.ocr-processing small { font-size: 12px; }

.ocr-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* OCR rows */
.ocr-row {
  display: grid;
  grid-template-columns: 110px 1fr 100px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.ocr-row:last-of-type { border-bottom: 0; }

.ocr-row span { color: var(--muted); font-size: 12px; }
.ocr-row em { font-style: normal; font-size: 11px; font-weight: 600; text-align: left; }

.conf-high  { color: #059669; }
.conf-medium { color: #d97706; }
.conf-low   { color: var(--danger); }

.ocr-note {
  margin-top: 10px;
  padding: 10px 12px;
  background: #eff6ff;
  border-radius: 10px;
  font-size: 12px;
  color: #1e40af;
}

.ocr-note small { display: block; }

/* ══════════════════════════════════════════
   FILTERS
══════════════════════════════════════════ */

.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.filters input { min-width: 260px; }

/* ══════════════════════════════════════════
   CALENDAR
══════════════════════════════════════════ */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.day {
  min-height: 90px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
  font-weight: 700;
}

.day small {
  display: block;
  margin-top: 12px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.day.muted { min-height: auto; background: #f8fafc; color: var(--muted); text-align: center; }
.active-day { background: #eff6ff; border-color: #93c5fd; }

/* ══════════════════════════════════════════
   REVIEW & PROBLEM CARDS
══════════════════════════════════════════ */

.review-card,
.problem-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 12px;
}

.review-card h4, .problem-card h4 { margin: 0 0 10px; }
.review-card p, .problem-card p { margin: 5px 0; }
.muted-text { color: var(--muted); }

.review-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.problem-card { background: #fef2f2; border-color: #fecaca; }

/* ══════════════════════════════════════════
   REPORTS
══════════════════════════════════════════ */

.report-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.report-grid button {
  min-height: 86px;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
}

.report-grid button:hover { background: #eff6ff; border-color: #93c5fd; }

/* ══════════════════════════════════════════
   TOAST NOTIFICATIONS
══════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: white;
  padding: 13px 18px;
  border-radius: 14px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
  pointer-events: auto;
  border-right: 4px solid var(--primary);
  max-width: 320px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { border-right-color: #22c55e; }
.toast.toast-warning { border-right-color: #f59e0b; }
.toast.toast-error   { border-right-color: var(--danger); }
.toast.toast-info    { border-right-color: var(--primary); }

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: static; }
  .nav { display: grid; grid-template-columns: repeat(3, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .report-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .main { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .metric-grid, .form-grid, .settings-grid { grid-template-columns: 1fr; }
  .nav { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 16px; overflow-x: auto; }
  .calendar-grid { grid-template-columns: repeat(2, 1fr); }
  .review-card, .problem-card { flex-direction: column; align-items: flex-start; }
  .ocr-row { grid-template-columns: 1fr; }
  .notif-panel { width: 300px; left: auto; right: 0; }
}
