/* ============================================================
   StockLedger — Main Stylesheet
   Light theme · DM Sans + Syne · Modern Admin UI
   ============================================================ */

/* ── Reset & Variables ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --bg:          #F5F4F0;
  --surface:     #FFFFFF;
  --surface-2:   #F9F8F5;
  --border:      #E8E6E0;
  --border-dark: #D4D0C8;

  --text:        #1A1916;
  --text-2:      #6B6860;
  --text-3:      #9C9990;

  --accent:      #2D6A4F;
  --accent-lt:   #E8F5EE;
  --accent-2:    #40916C;

  --blue:        #1E6091;
  --blue-lt:     #E8F1F8;
  --red:         #C0392B;
  --red-lt:      #FDECEA;
  --amber:       #D97706;
  --amber-lt:    #FEF3C7;
  --purple:      #6D28D9;
  --purple-lt:   #EDE9FE;

  /* Sidebar */
  --sidebar-w:   240px;
  --sidebar-bg:  #1A1916;
  --sidebar-text:#E8E6E0;
  --sidebar-muted:#6B6860;
  --sidebar-hover:#2A2925;
  --sidebar-active-bg: #2D6A4F;
  --sidebar-active: #FFFFFF;

  /* Misc */
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:   0 10px 30px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.05);

  /* Typography */
  --font-body:   'DM Sans', sans-serif;
  --font-head:   'Syne', sans-serif;

  --topbar-h:    60px;
  --transition:  0.18s ease;
}

html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-icon {
  font-size: 22px;
  color: var(--accent-2);
  line-height: 1;
}
.brand-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--sidebar-text);
  letter-spacing: 0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}
.nav-group {
  margin-bottom: 6px;
  padding: 0 12px;
}
.nav-group-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  padding: 12px 8px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #B0ADA6;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
}
.nav-link svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}
.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.user-details { min-width: 0; }
.user-name {
  display: block;
  font-size: 0.82rem; font-weight: 600;
  color: var(--sidebar-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role {
  display: block;
  font-size: 0.72rem;
  color: var(--sidebar-muted);
  text-transform: capitalize;
}
.btn-logout {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--sidebar-muted);
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-logout svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.btn-logout:hover { background: var(--sidebar-hover); color: var(--red); }

/* ── Main Wrapper ──────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border);
}
.sidebar-toggle {
  display: none;
  flex-direction: column; gap: 5px;
  cursor: pointer; background: none; border: none; padding: 4px;
}
.sidebar-toggle span {
  display: block; width: 20px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: all var(--transition);
}
.topbar-title {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* ── Page Content ───────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px 28px;
}

/* ── Flash Messages ─────────────────────────────────────────── */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  animation: slideIn 0.2s ease;
}
.flash-success { background: var(--accent-lt); color: var(--accent); border: 1px solid #A7D7BC; }
.flash-error   { background: var(--red-lt);    color: var(--red);    border: 1px solid #F5C6C2; }
.flash-warning { background: var(--amber-lt);  color: var(--amber);  border: 1px solid #FDE68A; }
.flash-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; line-height: 1; opacity: 0.6;
  padding: 0 0 0 4px;
}
.flash-close:hover { opacity: 1; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 18px 22px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.card-title {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}
.card-body { padding: 20px 22px; }
.card-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Stat Cards ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-top { display: flex; align-items: flex-start; justify-content: space-between; }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}
.stat-icon.green  { background: var(--accent-lt);  }
.stat-icon.blue   { background: var(--blue-lt);    }
.stat-icon.amber  { background: var(--amber-lt);   }
.stat-icon.purple { background: var(--purple-lt);  }
.stat-icon.red    { background: var(--red-lt);     }
.stat-badge {
  font-size: 0.72rem; font-weight: 600;
  padding: 3px 8px; border-radius: 20px;
}
.stat-badge.up   { background: var(--accent-lt); color: var(--accent); }
.stat-badge.down { background: var(--red-lt);    color: var(--red);    }
.stat-value {
  font-family: var(--font-head);
  font-size: 1.65rem; font-weight: 800;
  color: var(--text); line-height: 1.1;
}
.stat-label {
  font-size: 0.8rem; font-weight: 500;
  color: var(--text-2);
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead th {
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
.td-mono { font-variant-numeric: tabular-nums; font-weight: 500; }
.td-green { color: var(--accent); font-weight: 600; }
.td-red   { color: var(--red);    font-weight: 600; }
.td-amber { color: var(--amber);  font-weight: 600; }
.td-muted { color: var(--text-2); font-size: 0.82rem; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.72rem; font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: var(--accent-lt); color: var(--accent); }
.badge-red    { background: var(--red-lt);    color: var(--red); }
.badge-blue   { background: var(--blue-lt);   color: var(--blue); }
.badge-amber  { background: var(--amber-lt);  color: var(--amber); }
.badge-purple { background: var(--purple-lt); color: var(--purple); }
.badge-gray   { background: #F0EDE8;          color: var(--text-2); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.875rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
  border: none; transition: all var(--transition);
  line-height: 1.4; white-space: nowrap;
}
.btn svg {
  width: 15px; height: 15px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover  { background: var(--accent-2); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-dark); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger   { background: var(--red-lt); color: var(--red); border: 1px solid #F5C6C2; }
.btn-danger:hover   { background: #FDDDD9; }
.btn-blue     { background: var(--blue); color: #fff; }
.btn-blue:hover     { background: #1A5179; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon { padding: 8px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 0.8rem; font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.02em;
}
label .req { color: var(--red); margin-left: 2px; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.12);
}
input[readonly] { background: var(--surface-2); color: var(--text-2); cursor: default; }
textarea { resize: vertical; min-height: 90px; }
select { cursor: pointer; }
.form-hint { font-size: 0.76rem; color: var(--text-3); }
.form-error { font-size: 0.76rem; color: var(--red); }

/* ── Search & Filters ───────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.search-box {
  position: relative; flex: 1; min-width: 200px;
}
.search-box input {
  padding-left: 36px;
  background: var(--surface);
}
.search-box svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px;
  stroke: var(--text-3); fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  pointer-events: none;
}
.filter-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-row .form-group { margin: 0; min-width: 160px; flex: 1; }
.filter-row .form-group label { margin-bottom: 4px; }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 4px;
  flex-wrap: wrap;
}
.page-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.82rem; font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  cursor: pointer; text-decoration: none;
  transition: all var(--transition);
}
.page-btn:hover   { border-color: var(--accent); color: var(--accent); }
.page-btn.active  { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn.disabled { opacity: 0.4; pointer-events: none; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 999;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(0.96) translateY(-10px); } to { opacity:1; transform: scale(1) translateY(0); } }
.modal-header {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-family: var(--font-head); font-size: 1rem; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px;
  background: var(--surface-2); border: none;
  border-radius: 7px; font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: all var(--transition);
}
.modal-close:hover { background: var(--red-lt); color: var(--red); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 14px 24px 20px;
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
  margin-bottom: 24px;
}
.page-header-left {}
.page-header h1 {
  font-family: var(--font-head);
  font-size: 1.35rem; font-weight: 800;
  color: var(--text);
}
.page-header p {
  font-size: 0.85rem; color: var(--text-2);
  margin-top: 3px;
}

/* ── Login Page ─────────────────────────────────────────────── */
body.login-body {
  justify-content: center; align-items: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px;
  padding: 40px 36px;
}
.login-logo {
  text-align: center;
  margin-bottom: 30px;
}
.login-logo .brand-icon { font-size: 2rem; color: var(--accent); }
.login-logo h1 {
  font-family: var(--font-head);
  font-size: 1.4rem; font-weight: 800;
  margin-top: 8px; color: var(--text);
}
.login-logo p { font-size: 0.85rem; color: var(--text-2); margin-top: 4px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; padding: 12px; }
.login-demo {
  margin-top: 16px; font-size: 0.78rem; color: var(--text-3);
  text-align: center; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}

/* ── Report specific ─────────────────────────────────────────── */
.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.report-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.report-stat .value {
  font-family: var(--font-head);
  font-size: 1.4rem; font-weight: 800;
  color: var(--text);
}
.report-stat .label { font-size: 0.78rem; color: var(--text-2); margin-top: 4px; }

/* ── Utility ─────────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.fw-bold     { font-weight: 700; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.empty-state {
  text-align: center; padding: 50px 20px;
  color: var(--text-3);
}
.empty-state svg {
  width: 48px; height: 48px;
  stroke: var(--border-dark); fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  margin-bottom: 14px;
}
.empty-state p { font-size: 0.875rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .page-content { padding: 18px 16px; }
  .topbar { padding: 0 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ── Overlay (mobile sidebar close) ─────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }

/* ── Profit indicator pill in tables ───────────────────────── */
.profit-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600;
}
.profit-pill.pos { background: var(--accent-lt); color: var(--accent); }
.profit-pill.neg { background: var(--red-lt);    color: var(--red);    }
