@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,600;0,700;1,600;1,700&family=DM+Sans:wght@300;400;500&display=swap');

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

:root {
  --navy: #1e3a5f;
  --navy-dark: #152b47;
  --navy-deep: #0d1e33;
  --navy-mid: #2d5a8f;
  --navy-light: #e8eef5;
  --gold: #b8956a;
  --gold-light: #f5ede0;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #dde4ed;
  --text: #1a1a1a;
  --text-muted: #8a8a8a;
  --text-light: #4a4a4a;
  --green: #2a7a6b;
  --green-light: #e6f4f1;
  --red: #ef4444;
  --red-light: #fef2f2;
  --amber: #b8956a;
  --amber-light: #f5ede0;
  --blue: #1e3a5f;
  --blue-light: #e8eef5;
  --purple: #4a2d7a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --sidebar-bg: #0d1e33;
  --sidebar-active: rgba(255,255,255,0.1);
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-text: rgba(255,255,255,0.65);
  --sidebar-text-active: #ffffff;
  --sidebar-border: rgba(255,255,255,0.08);
}

body.dark {
  --bg: #0a1520;
  --surface: #112035;
  --border: #1a3050;
  --text: #e8eef5;
  --text-muted: #4d6480;
  --text-light: #94a3b8;
  --navy-light: #0d1e33;
  --sidebar-bg: #071018;
}

body {
  overflow-x: hidden;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Login ── */
.login-screen {
  min-height: 100vh;
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 40%, var(--navy-deep) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 1000;
}
.login-card {
  width: 100%;
  max-width: 400px;
}
.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-badge {
  width: 52px;
  height: 52px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
}
.login-wordmark {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  color: #fff;
}
.login-tagline {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  margin-top: 4px;
}
.login-form {
  background: rgba(255,255,255,0.97);
  border-radius: 16px;
  padding: 2rem;
  border: 0.5px solid rgba(255,255,255,0.1);
}
.login-form-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.5rem;
}
.login-form input {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 1rem;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.login-form input:focus { border-color: var(--navy); }
.login-form button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  margin-top: 0.5rem;
}
.login-form button:hover { opacity: 0.9; }
.login-error {
  background: #fef2f2;
  color: #dc2626;
  border: 0.5px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 1rem;
  font-size: 13px;
  display: none;
}

/* ── Top Bar ── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--navy-deep);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 1.25rem;
  height: 56px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.top-bar h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex: 1;
}
.menu-toggle {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 6px;
}
.menu-toggle:hover { background: rgba(255,255,255,0.1); }

/* ── Sidebar ── */
nav.side-nav {
  position: fixed;
  top: 56px;
  left: 0;
  height: calc(100vh - 56px);
  width: 220px;
  background: var(--sidebar-bg);
  z-index: 99;
  transition: transform 0.2s;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
nav.side-nav.collapsed { transform: translateX(-100%); }
.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.sidebar-badge {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}
.sidebar-brand { line-height: 1.3; }
.sidebar-subtitle {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.user-display {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
}
nav.side-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 8px;
  margin: 2px 8px;
  width: calc(100% - 16px);
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  letter-spacing: 0.02em;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
nav.side-nav button .material-icons { font-size: 18px; color: inherit; flex-shrink: 0; }
nav.side-nav button span:not(.material-icons) { font-size: 12px; font-weight: 500; }
nav.side-nav button:hover { background: var(--sidebar-hover); color: #fff; }
nav.side-nav button.active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
#userTabs, #adminTabs { padding: 8px 0; }
.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-footer .btn {
  justify-content: flex-start;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  border-color: transparent;
  background: transparent;
}
.sidebar-footer .btn:hover { background: rgba(255,255,255,0.06); color: #fff; }

/* ── Main Content ── */
main.with-sidebar { margin-left: 220px; background: var(--bg); min-height: calc(100vh - 56px); }
nav.side-nav.collapsed ~ main.with-sidebar { margin-left: 0; width: 100%; }
main#content { padding: 24px 28px; }

/* ── Section Title ── */
.section-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  letter-spacing: -0.02em;
}
.section-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  margin-top: 4px;
}

/* ── Skeletons ── */
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card { height: 80px; border-radius: var(--radius); }
.skeleton-row { height: 14px; margin-bottom: 10px; }

/* ── Stat Cards ── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 1.5rem; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--navy); }
.card--green::before { background: var(--green); }
.card--red::before { background: var(--red); }
.card--blue::before { background: var(--navy); }
.card--purple::before { background: var(--purple); }
.card-label { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.card-value { font-family: 'Playfair Display', Georgia, serif; font-size: 20px; font-weight: 700; color: var(--text); line-height: 1; }
.card--green .card-value { color: var(--green); }
.card--red .card-value { color: var(--red); }
.card--blue .card-value { color: var(--navy); }

/* ── Forms ── */
.add-form {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  box-shadow: var(--shadow);
}
.add-form input, .add-form select, .add-form textarea {
  flex: 1 1 160px;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
body.dark .add-form input,
body.dark .add-form select,
body.dark .add-form textarea {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
body.dark select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
body.dark input, body.dark textarea {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
body.dark .login-form {
  background: rgba(17, 32, 53, 0.98);
}
body.dark .login-form input {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
body.dark .login-form-title { color: var(--text); }
.add-form input:focus, .add-form select:focus, .add-form textarea:focus { border-color: var(--navy); }
.add-form textarea { min-height: 60px; resize: vertical; }
select {
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  outline: none;
}
select:focus { border-color: var(--navy); }

/* ── Buttons ── */
.btn {
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: linear-gradient(135deg, var(--navy), var(--navy-dark)); color: #fff; border: none; border-radius: 8px; padding: 8px 18px; font-size: 13px; font-weight: 500; font-family: 'DM Sans', sans-serif; cursor: pointer; }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 0.5px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 14px; text-align: left; font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); white-space: nowrap; background: var(--bg); border-bottom: 0.5px solid var(--border); }
td { padding: 10px 14px; font-size: 13px; color: var(--text); border-bottom: 0.5px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--navy-light); }
body.dark tr:hover td { background: rgba(30,58,95,0.25); }
body.dark th { background: rgba(255,255,255,0.04); color: var(--text-muted); }
body.dark td { color: var(--text); }
body.dark .table-wrap { border-color: var(--border); }
.debit { color: var(--red); font-weight: 600; }
.credit { color: var(--green); font-weight: 600; }

/* ── Badges ── */
.badge { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.badge--green, .badge--confirmed, .badge--completed, .badge--active, .badge--available, .badge--in-stock { background: var(--green-light); color: var(--green); }
.badge--red, .badge--cancelled, .badge--inactive { background: var(--red-light); color: var(--red); }
.badge--amber, .badge--pending, .badge--unpaid { background: var(--amber-light); color: #92400e; }
.badge--blue, .badge--processing { background: var(--blue-light); color: var(--navy); }
.badge--gray { background: var(--border); color: var(--text-muted); }
.badge--purple { background: #ede9fe; color: #5b21b6; }
body.dark .badge--purple { background: #2e1065; color: #c4b5fd; }
body.dark .badge--green { background: #064e3b; color: #34d399; }
body.dark .badge--red { background: #450a0a; color: #f87171; }
body.dark .badge--amber { background: #451a03; color: #fbbf24; }
body.dark .badge--blue { background: #172554; color: #93c5fd; }

/* ── Avatar ── */
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 600; font-size: 12px; margin-right: 8px; vertical-align: middle; flex-shrink: 0; }

/* ── Search ── */
.stock-search-wrap { position: relative; margin-bottom: 1rem; }
.stock-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 18px; color: var(--text-muted); pointer-events: none; }
.stock-search-input { width: 100%; padding: 9px 2.5rem 9px 2.5rem; border: 0.5px solid var(--border); border-radius: 8px; font-size: 13px; font-family: 'DM Sans', sans-serif; background: var(--surface); color: var(--text); outline: none; }
.stock-search-input:focus { border-color: var(--navy); }
.stock-clear-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 18px; color: var(--text-muted); cursor: pointer; }
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); font-size: 14px; }

/* ── Toast ── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--surface); border: 0.5px solid var(--border); border-left: 3px solid var(--navy); border-radius: 10px; padding: 12px 20px; font-size: 13px; color: var(--text); box-shadow: 0 8px 32px rgba(0,0,0,0.15); transform: translateY(80px); opacity: 0; transition: all 0.3s ease; z-index: 999; max-width: 320px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-left-color: var(--red); }

/* ── Toolbar ── */
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }

/* ── Row Actions ── */
.row-actions { white-space: nowrap; text-align: right; }
.btn-icon { background: transparent; border: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 14px; opacity: 0.4; transition: opacity 0.15s, background 0.15s; }
.btn-icon:hover { opacity: 1; }
.btn-delete:hover { background: var(--red-light); }
.btn-edit:hover { background: var(--blue-light); }
tr:hover .btn-icon { opacity: 0.7; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 200; justify-content: center; align-items: center; padding: 20px; }
.modal-overlay.active { display: flex; }
.modal { background: var(--surface); border: 0.5px solid var(--border); border-radius: 16px; width: 100%; max-width: 560px; box-shadow: 0 24px 64px rgba(0,0,0,0.2); animation: modalIn 0.2s ease; overflow-y: auto; max-height: 90vh; }
body.dark .modal { background: var(--surface); color: var(--text); }
body.dark .modal input, body.dark .modal select, body.dark .modal textarea {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
@keyframes modalIn { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-header h2 { font-family: 'Playfair Display', Georgia, serif; font-size: 18px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 8px; background: transparent; border: 0.5px solid var(--border); color: var(--text-muted); font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 20px; }

/* ── Cashflow ── */
.cashflow-wrap { display: flex; flex-direction: column; gap: 1.5rem; }
.cashflow-section-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 0.5px solid var(--border);
}
.cashflow-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.summary-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.summary-label { display: block; font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 6px; }
.summary-value { font-family: 'Playfair Display', Georgia, serif; font-size: 20px; font-weight: 700; color: var(--text); }
.summary-total { border-color: var(--navy); }
.summary-total .summary-value { color: var(--navy); }
.cashflow-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
.denom-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.denom-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--navy); }
.denom-input { width: 100%; border: 0.5px solid var(--border); border-radius: 8px; padding: 6px; text-align: center; font-size: 15px; font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); outline: none; }
.denom-input:focus { border-color: var(--navy); }
.denom-sub { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.cashflow-totals { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1.25rem; display: flex; flex-direction: column; gap: 8px; }
.cashflow-totals p { font-size: 14px; color: var(--text-muted); }
.grand-total { font-size: 16px !important; font-weight: 700; color: var(--navy) !important; }

/* ── Charts ── */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.chart-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.chart-card canvas { max-height: 240px; }

/* ── Admin ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card .stat-value { font-family: 'Playfair Display', Georgia, serif; font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* ── Settings ── */
.settings-sections section { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1.5rem; max-width: 500px; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.settings-sections h3 { font-family: 'Playfair Display', Georgia, serif; font-size: 16px; font-weight: 700; margin-bottom: 1rem; }

/* ── Bottom Nav (mobile) ── */
nav.bottom-nav { display: none; }
@media (max-width: 768px) {
  nav.side-nav { transform: translateX(-100%); top: 56px; height: calc(100vh - 56px); }
  nav.side-nav.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.3); }
  main.with-sidebar { margin-left: 0 !important; width: 100% !important; }
  nav.bottom-nav {
    display: flex !important;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--navy-deep);
    border-top: 0.5px solid rgba(255,255,255,0.08);
    z-index: 98;
    justify-content: space-around;
    padding: 6px 0;
  }
  nav.bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    background: transparent; border: none;
    color: rgba(255,255,255,0.45);
    font-size: 9px; font-weight: 500; font-family: 'DM Sans', sans-serif;
    text-transform: uppercase; letter-spacing: 0.3px;
    cursor: pointer; padding: 4px 8px; border-radius: 0;
  }
  nav.bottom-nav button .material-icons { font-size: 20px; }
  nav.bottom-nav button.active { color: #fff; }
  main#content { padding-bottom: 70px; padding: 16px 16px 70px; }
}

/* ── Admin tab visibility ── */
#adminTabs { display: none; }
