/* ==========================================================================
   Bookkeeper — core stylesheet
   ========================================================================== */

:root {
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-light: #EEF2FF;
  --success: #16A34A;
  --success-light: #DCFCE7;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --info: #0891B2;
  --info-light: #CFFAFE;
  --muted: #6B7280;
  --muted-light: #F3F4F6;

  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.10), 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);

  --sidebar-w: 250px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0 0 0.5em; }
ul { margin: 0; padding: 0; list-style: none; }
button { font-family: inherit; }

/* ---------------------------------------------------------------------- */
/* App shell                                                              */
/* ---------------------------------------------------------------------- */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #14103A;
  background: linear-gradient(180deg, #171442 0%, #14103A 100%);
  color: #E4E1FA;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 22px 18px;
  font-weight: 800;
  font-size: 1.15rem;
  color: #fff;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: #C7C2EE;
  font-weight: 500;
  font-size: 0.92rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.nav-link.active {
  background: var(--primary);
  color: #fff;
}

.nav-link-muted { color: #9791C4; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 35, 0.5);
  z-index: 35;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.topbar-spacer { flex: 1; }

.sidebar-toggle { display: none; }

.icon-btn {
  border: none;
  background: transparent;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--muted-light); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-company {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.content {
  flex: 1;
  padding: 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ---------------------------------------------------------------------- */
/* Page header / toolbar                                                  */
/* ---------------------------------------------------------------------- */

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-toolbar h2 {
  font-size: 1.05rem;
  color: var(--text-muted);
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--muted-light); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--muted-light); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------------- */
/* Cards / stat tiles                                                     */
/* ---------------------------------------------------------------------- */

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

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

.card-header h3 { font-size: 1rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.amber { background: var(--warning-light); color: var(--warning); }

.stat-value { font-size: 1.55rem; font-weight: 800; }
.stat-sub { font-size: 0.78rem; color: var(--text-muted); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-wrap { position: relative; height: 280px; }
.chart-wrap.small { height: 220px; }

/* ---------------------------------------------------------------------- */
/* Tables                                                                 */
/* ---------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

.data-table th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #FAFAFE; }
.data-table tbody tr:last-child td { border-bottom: none; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }

.cell-title { font-weight: 600; }
.cell-sub { font-size: 0.8rem; color: var(--text-muted); }

.amount-income { color: var(--success); font-weight: 700; }
.amount-expense { color: var(--danger); font-weight: 700; }
.amount-transfer { color: var(--info); font-weight: 700; }

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 2.4rem; color: var(--border); margin-bottom: 12px; display: block; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

/* ---------------------------------------------------------------------- */
/* Badges / pills / avatars                                               */
/* ---------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: capitalize;
}

.badge-success { background: var(--success-light); color: #15803D; }
.badge-warning { background: var(--warning-light); color: #B45309; }
.badge-danger  { background: var(--danger-light); color: #B91C1C; }
.badge-info    { background: var(--info-light); color: #0E7490; }
.badge-muted   { background: var(--muted-light); color: var(--text-muted); }

.pill-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------------- */
/* Forms                                                                  */
/* ---------------------------------------------------------------------- */

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

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-grid .form-group { margin-bottom: 0; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.field-hint { font-size: 0.76rem; color: var(--text-muted); }

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=date],
input[type=search],
input[type=tel],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input-prefix-group {
  display: flex;
  align-items: stretch;
}
.input-prefix-group .prefix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--muted-light);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
}
.input-prefix-group input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  align-items: flex-end;
}
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }
.filter-bar label { font-size: 0.72rem; color: var(--text-muted); }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------------------------------------------------------------------- */
/* Alerts                                                                 */
/* ---------------------------------------------------------------------- */

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-weight: 500;
  font-size: 0.88rem;
}
.alert-success { background: var(--success-light); color: #15803D; }
.alert-error, .alert-danger { background: var(--danger-light); color: #B91C1C; }
.alert-info { background: var(--info-light); color: #0E7490; }

/* ---------------------------------------------------------------------- */
/* Modal                                                                  */
/* ---------------------------------------------------------------------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: 5vh;
}
.modal.modal-lg { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; }

.modal-body { padding: 22px; max-height: 70vh; overflow-y: auto; }
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------------------------------------------------------------------- */
/* Auth pages                                                             */
/* ---------------------------------------------------------------------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #171442 0%, #4F46E5 100%);
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 36px 32px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 22px;
  font-weight: 800;
  font-size: 1.3rem;
}

.auth-card h1 { font-size: 1.3rem; text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-muted); margin-bottom: 24px; font-size: 0.88rem; }
.auth-footer { text-align: center; margin-top: 18px; font-size: 0.86rem; color: var(--text-muted); }
.auth-footer a { color: var(--primary); font-weight: 600; }

/* ---------------------------------------------------------------------- */
/* Invoice document                                                       */
/* ---------------------------------------------------------------------- */

.invoice-doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-sm);
}

.invoice-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.invoice-doc-header h2 { font-size: 1.6rem; letter-spacing: 0.02em; }

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}

.invoice-parties .label { font-size: 0.72rem; text-transform: uppercase; color: var(--text-muted); font-weight: 700; margin-bottom: 6px; letter-spacing: 0.04em; }

.invoice-meta-table { font-size: 0.85rem; }
.invoice-meta-table td { padding: 3px 0; }
.invoice-meta-table td:first-child { color: var(--text-muted); padding-right: 14px; }
.invoice-meta-table td:last-child { font-weight: 600; text-align: right; }

.invoice-totals {
  margin-left: auto;
  width: 280px;
  margin-top: 10px;
}
.invoice-totals-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 0.9rem; }
.invoice-totals-row.grand { border-top: 2px solid var(--text); font-size: 1.1rem; font-weight: 800; padding-top: 12px; }
.invoice-totals-row.paid { color: var(--success); }
.invoice-totals-row.due { font-weight: 800; color: var(--primary); }

/* ---------------------------------------------------------------------- */
/* Misc utilities                                                         */
/* ---------------------------------------------------------------------- */

.text-muted { color: var(--text-muted); }
.mb-0 { margin-bottom: 0 !important; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-link {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.tab-link.active { color: var(--primary); border-color: var(--primary); }

/* ---------------------------------------------------------------------- */
/* Responsive                                                             */
/* ---------------------------------------------------------------------- */

@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  :root { --topbar-h: 58px; }

  .sidebar {
    transform: translateX(-100%);
    width: 240px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop.open { display: block; }

  .main { margin-left: 0; }
  .sidebar-toggle { display: flex; }

  .content { padding: 16px; }

  .form-grid { grid-template-columns: 1fr; }
  .invoice-parties { grid-template-columns: 1fr; }

  .user-company { display: none; }

  .invoice-doc { padding: 22px; }
  .invoice-totals { width: 100%; }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .modal { max-width: 100%; border-radius: var(--radius); }
}

/* ---------------------------------------------------------------------- */
/* Print (invoice view)                                                   */
/* ---------------------------------------------------------------------- */

@media print {
  .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0; max-width: 100%; }
  body { background: #fff; }
  .invoice-doc { border: none; box-shadow: none; padding: 0; }
}
