:root {
  --blue-900: #0B2559;
  --blue-700: #1E4FD9;
  --blue-600: #2F6FED;
  --blue-500: #4C7EF3;
  --blue-300: #A9C4FF;
  --blue-100: #EAF1FF;
  --blue-50: #F5F9FF;
  --white: #FFFFFF;
  --ink: #101828;
  --ink-soft: #667085;
  --border: #E7ECF6;
  --success: #12B76A;
  --success-bg: #ECFDF3;
  --danger: #F04438;
  --danger-bg: #FEF3F2;
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-card: 0 10px 30px rgba(11, 37, 89, 0.06);
  --shadow-pop: 0 20px 50px rgba(11, 37, 89, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--white);
  color: var(--ink);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand, .nav-item, .btn, .stat-value {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
}

button, input, select { font-family: inherit; }

a { color: inherit; text-decoration: none; }

/* ---------- Blob decorations ---------- */
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(0px);
  pointer-events: none;
  z-index: 0;
}
.blob-soft { filter: blur(60px); opacity: 0.55; }

/* ---------- Login page ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--white);
}
.login-screen .blob-a {
  width: 620px; height: 620px;
  top: -220px; right: -180px;
  background: radial-gradient(circle at 30% 30%, var(--blue-600), var(--blue-900));
}
.login-screen .blob-b {
  width: 420px; height: 420px;
  bottom: -180px; left: -140px;
  background: radial-gradient(circle at 60% 40%, var(--blue-300), var(--blue-600));
}
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 44px 40px;
  border: 1px solid var(--border);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-logo .mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}
.login-logo span {
  font-weight: 800;
  font-size: 20px;
  color: var(--blue-900);
}
.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--ink);
}
.login-card p.sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 28px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 14px;
  color: var(--ink);
  background: var(--blue-50);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.field input:focus, .field select:focus {
  border-color: var(--blue-600);
  background: var(--white);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--blue-600), var(--blue-900));
  color: var(--white);
  width: 100%;
  box-shadow: 0 10px 24px rgba(47, 111, 237, 0.28);
}
.btn-primary:hover { opacity: 0.94; }
.btn-secondary {
  background: var(--blue-100);
  color: var(--blue-700);
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--border);
}
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; background: var(--blue-50); }

.sidebar {
  width: 250px;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.sidebar .blob {
  width: 260px; height: 260px;
  bottom: -120px; left: -100px;
  background: radial-gradient(circle, var(--blue-100), transparent 70%);
  z-index: 0;
}
.sidebar-inner { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100%; }
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 24px;
}
.brand .mark {
  width: 32px; height: 32px; border-radius: 9px;
  object-fit: cover;
  flex-shrink: 0;
}
.brand span { font-weight: 800; font-size: 18px; color: var(--blue-900); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--blue-50); color: var(--blue-700); }
.nav-item.active {
  background: linear-gradient(135deg, var(--blue-600), var(--blue-700));
  color: var(--white);
  box-shadow: 0 8px 20px rgba(47, 111, 237, 0.25);
}
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.7; flex-shrink: 0; }
.nav-group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-soft); opacity: 0.6;
  padding: 18px 14px 6px;
}
.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-900));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-chip .info { min-width: 0; }
.user-chip .name { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .logout { font-size: 12px; color: var(--danger); cursor: pointer; font-weight: 600; }

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

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.topbar h2 { margin: 0; font-size: 19px; font-weight: 700; }
.company-switcher { position: relative; }
.company-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--blue-100);
  color: var(--blue-700);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  border: none;
}
.company-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-pop);
  width: 260px; padding: 8px; z-index: 50;
}
.company-option {
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.company-option:hover { background: var(--blue-50); }
.company-option.current { color: var(--blue-700); background: var(--blue-50); }

.content { padding: 28px 32px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 24px;
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.card-header h3 { margin: 0; font-size: 16px; font-weight: 700; }
.card-header .desc { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--white);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 20px;
  position: relative; overflow: hidden;
}
.stat-card .blob { width: 130px; height: 130px; top: -50px; right: -50px; background: radial-gradient(circle, var(--blue-100), transparent 70%); }
.stat-card .label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; position: relative; z-index: 1; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--blue-900); margin-top: 6px; position: relative; z-index: 1; }
.stat-card.accent { background: linear-gradient(135deg, var(--blue-600), var(--blue-900)); border: none; }
.stat-card.accent .label { color: rgba(255,255,255,0.75); }
.stat-card.accent .stat-value { color: white; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--ink-soft); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 12px; border-bottom: 1.5px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); color: var(--ink); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--blue-50); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }

.badge {
  display: inline-flex; align-items: center; padding: 4px 10px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-draft { background: var(--blue-100); color: var(--blue-700); }
.badge-posted { background: var(--success-bg); color: var(--success); }
.badge-void { background: var(--danger-bg); color: var(--danger); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--ink-soft); }
.empty-state .blob { width: 160px; height: 160px; left: 50%; top: 0; transform: translateX(-50%); background: radial-gradient(circle, var(--blue-100), transparent 70%); }
.empty-state p { position: relative; z-index: 1; font-size: 14px; margin: 8px 0 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.line-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1.4fr auto; gap: 10px; align-items: end; margin-bottom: 10px; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--blue-50); padding: 5px; border-radius: 999px; width: fit-content; }
.tab {
  padding: 9px 18px; border-radius: 999px; font-size: 13px; font-weight: 700;
  cursor: pointer; color: var(--ink-soft);
}
.tab.active { background: var(--white); color: var(--blue-700); box-shadow: var(--shadow-card); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(11, 37, 89, 0.35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--white); border-radius: var(--radius-lg);
  padding: 28px; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-pop);
}
.modal h3 { margin: 0 0 18px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  background: var(--ink); color: white; padding: 12px 18px;
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-pop);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.balance-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 6px 12px; border-radius: 999px; }
.balance-ok { background: var(--success-bg); color: var(--success); }
.balance-bad { background: var(--danger-bg); color: var(--danger); }

.hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 20px; }
  .topbar { padding: 14px 20px; }
  .line-row { grid-template-columns: 1fr; }
}
