:root {
  color-scheme: light;
  --bg: #0c1117;
  --bg-accent: #1a2a3f;
  --panel: rgba(16, 23, 33, 0.92);
  --panel-strong: rgba(20, 28, 40, 0.98);
  --panel-border: rgba(100, 160, 220, 0.1);
  --text: #e8f0f8;
  --muted: #8ba3b8;
  --primary: #6c8cff;
  --primary-strong: #8da8ff;
  --primary-glow: rgba(108, 140, 255, 0.15);
  --success: #34d399;
  --success-glow: rgba(52, 211, 153, 0.12);
  --danger: #f87171;
  --danger-glow: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --warning-glow: rgba(251, 191, 36, 0.12);
  --focus: #6c8cff;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  --glass: rgba(255, 255, 255, 0.04);
  --radius-xl: 1.5rem;
  --radius-lg: 1.25rem;
  --radius-md: 0.875rem;
  --radius-sm: 0.625rem;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f0f2f5;
  --bg-accent: #dfe4ea;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --panel-border: rgba(0, 0, 0, 0.08);
  --text: #1a1d23;
  --muted: #6b7280;
  --primary: #4f6cf7;
  --primary-strong: #3b55d9;
  --primary-glow: rgba(79, 108, 247, 0.08);
  --success: #059669;
  --success-glow: rgba(5, 150, 105, 0.08);
  --danger: #dc2626;
  --danger-glow: rgba(220, 38, 38, 0.08);
  --warning: #d97706;
  --warning-glow: rgba(217, 119, 6, 0.08);
  --focus: #4f6cf7;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.06);
  --glass: rgba(0, 0, 0, 0.02);
}

/* ─── Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { min-height: 100vh; overflow-x: hidden; font-family: "Inter", system-ui, sans-serif; color: var(--text); background: var(--bg); font-size: 0.9375rem; line-height: 1.6; }
button, input, select, textarea, a { font: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ─── Background ────────────────────────────────────────── */
.app-bg { position: fixed; inset: 0; z-index: -1; background: radial-gradient(ellipse at 20% 20%, var(--primary-glow), transparent 50%), radial-gradient(ellipse at 80% 80%, var(--success-glow), transparent 50%), var(--bg); }

/* ─── Mobile First Layout (Base) ────────────────────────── */
.page-shell { padding: 1rem 0.75rem 6rem; max-width: 100%; margin: 0 auto; }
.layout-grid { display: grid; gap: 0.75rem; margin-bottom: 1.25rem; grid-template-columns: 1fr; }
.stats-grid { display: grid; gap: 0.5rem; margin-bottom: 1rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }
.section-title h2 { font-size: 1.125rem; font-weight: 700; }

/* ─── Mobile Topbar & Nav ───────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 100; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.75rem 1rem; background: var(--panel); border-bottom: 1px solid var(--panel-border); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.topbar__brand { display: flex; align-items: center; gap: 0.5rem; }
.topbar__logo { font-size: 1.25rem; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--success)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.topbar__nav { display: none; } /* Hidden on mobile */
.topbar__actions { display: flex; align-items: center; gap: 0.5rem; }
.topbar__user { display: none; } /* Hidden on mobile */

.mobile-bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 200; background: var(--panel); border-top: 1px solid var(--panel-border); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); padding: 0.25rem 0.25rem calc(0.25rem + env(safe-area-inset-bottom)); justify-content: space-around; overflow-x: auto; scrollbar-width: none; }
.mobile-bottom-nav::-webkit-scrollbar { display: none; }
.mobile-bottom-nav button { flex: 1 0 auto; min-width: 4rem; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; padding: 0.4rem 0.25rem; background: transparent; border: none; color: var(--muted); font-size: 0.6rem; font-weight: 700; cursor: pointer; border-radius: var(--radius-sm); text-transform: uppercase; }
.mobile-bottom-nav button .nav-icon { font-size: 1.25rem; line-height: 1; }
.mobile-bottom-nav button.tab-bar__btn--active { color: var(--primary); background: var(--primary-glow); }

/* ─── Touch Friendly Elements (Forms & Buttons) ─────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem; padding: 0.6rem 1rem; min-height: 3rem; /* 48px target */ border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 0.875rem; font-weight: 700; cursor: pointer; transition: all 0.15s ease; white-space: nowrap; }
.btn--sm { min-height: 2.25rem; padding: 0.35rem 0.65rem; font-size: 0.8125rem; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--success { background: var(--success); color: #fff; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--panel-border); }
.btn--block { width: 100%; }
.btn:active { transform: scale(0.96); }

.form-group { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 0.75rem; }
.form-group label { font-size: 0.8125rem; font-weight: 700; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.form-grid--full { grid-column: 1 / -1; }

input, select, textarea { width: 100%; padding: 0.7rem 0.85rem; min-height: 3rem; /* 48px touch target */ border: 1px solid var(--panel-border); border-radius: var(--radius-sm); background: var(--panel-strong); color: var(--text); font-size: 1rem; /* Prevent iOS zoom */ transition: border-color 0.15s ease; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.6; }

/* ─── Cards & Panels ────────────────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius-lg); padding: 1rem; overflow: hidden; margin-bottom: 0.75rem; }
.panel__header { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.panel__title { font-size: 1rem; font-weight: 700; }
.panel__label { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; color: var(--primary); }

.groups-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.75rem; }
.group-card { padding: 1.25rem; border-radius: var(--radius-lg); background: var(--panel); border: 1px solid var(--panel-border); cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.group-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.group-card__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }

.stat-card { padding: 1rem; border-radius: var(--radius-md); background: var(--panel-strong); border: 1px solid var(--panel-border); }
.stat-card__label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.stat-card__value { font-size: 1.5rem; font-weight: 800; margin-top: 0.25rem; }

.stack-list { display: grid; gap: 0.5rem; }
.stack-card { padding: 0.875rem; border-radius: var(--radius-md); border: 1px solid var(--panel-border); background: var(--panel-strong); }
.stack-card__row { display: flex; flex-direction: column; gap: 0.375rem; }
.stack-card strong { font-size: 0.875rem; }
.stack-card p { font-size: 0.8125rem; color: var(--muted); }
.stack-card .meta { font-size: 0.75rem; color: var(--muted); }
.stack-card .amount { font-weight: 800; color: var(--primary); align-self: flex-start; }

.request-card { padding: 0.875rem; border-radius: var(--radius-md); border: 1px solid var(--panel-border); background: var(--panel-strong); }
.request-card__header { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 0.5rem; }
.request-card__actions { display: flex; gap: 0.5rem; width: 100%; margin-top: 0.75rem; }
.request-card__actions .btn { flex: 1; }

.user-card { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; padding: 1rem; border: 1px solid var(--panel-border); border-radius: var(--radius-md); background: var(--panel-strong); }
.user-card > div:last-child { display: flex; justify-content: space-between; align-items: center; }

/* ─── Mobile Table (Card View) ──────────────────────────── */
.table-wrap { overflow-x: hidden; }
table, thead, tbody, tr, td, th { display: block; width: 100%; }
thead { display: none; }
tbody { display: grid; gap: 0.75rem; }
tr { border: 1px solid var(--panel-border); border-radius: var(--radius-md); padding: 0.875rem; background: var(--panel-strong); position: relative; }
td { border-bottom: none; padding: 0.25rem 0; font-size: 0.875rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
td::before { content: attr(data-label); font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; color: var(--muted); flex-shrink: 0; width: 35%; text-align: left; }
td[colspan] { justify-content: center; text-align: center; }
td[colspan]::before { content: none; }
.product-cell { text-align: right; }
.product-cell strong { display: block; font-size: 0.9375rem;}
.product-cell span { font-size: 0.75rem; color: var(--muted); }

.action-buttons { display: flex; flex-direction: column; gap: 0.5rem; width: 100%; margin-top: 0.5rem; }
td[data-label="Action"] { display: block; padding-top: 0.75rem; border-top: 1px dashed var(--panel-border); margin-top: 0.5rem; }
td[data-label="Action"]::before { display: none; }

/* ─── UI Components ─────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; padding: 0.25rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.pill--healthy { background: var(--success-glow); color: var(--success); }
.pill--low { background: var(--danger-glow); color: var(--danger); }
.pill--pending { background: var(--warning-glow); color: var(--warning); }
.pill--default { background: var(--glass); color: var(--muted); }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.25rem; height: 1.25rem; padding: 0 0.35rem; border-radius: 999px; font-size: 0.6875rem; font-weight: 800; background: var(--danger); color: #fff; line-height: 1; }
.badge-btn { font-size: 1.1rem; padding: 0.25rem 0.5rem; border-radius: var(--radius-sm); transition: background 0.15s ease; cursor: pointer; }
.badge-btn:hover { background: var(--glass); }

.search-box { display: flex; flex-direction: column; gap: 0.375rem; width: 100%; }
.empty-state { padding: 2rem 1rem; text-align: center; color: var(--muted); border-radius: var(--radius-md); border: 1px dashed var(--panel-border); }
.chart-surface { padding: 0.5rem; border-radius: var(--radius-md); background: var(--panel-strong); border: 1px solid var(--panel-border); overflow-x: auto; }
.chart { width: 100%; min-width: 400px; height: auto; display: block; color: var(--text); }
.theme-toggle { background: var(--glass); border: 1px solid var(--panel-border); border-radius: var(--radius-sm); color: var(--muted); font-weight: 700; padding: 0.5rem 0.75rem; cursor: pointer; }
.meta { font-size: 0.75rem; color: var(--muted); }

/* ─── Modals ────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 999; display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.modal--open { opacity: 1; pointer-events: auto; }
.modal__overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal__content { position: relative; z-index: 1000; width: 100%; max-width: 32rem; max-height: calc(100vh - 2rem); overflow-y: auto; background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius-xl); padding: 1.25rem; transform: translateY(20px) scale(0.95); transition: transform 0.2s ease; }
.modal--open .modal__content { transform: translateY(0) scale(1); }

/* ─── Login ─────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 26rem; background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius-xl); padding: 2rem 1.5rem; box-shadow: var(--shadow); }
.login-card__logo { font-size: 1.5rem; font-weight: 800; text-align: center; background: linear-gradient(135deg, var(--primary), var(--success)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-card__subtitle { text-align: center; font-size: 0.875rem; color: var(--muted); margin-bottom: 1.5rem; }
.login-toggle { text-align: center; margin-top: 1.5rem; font-size: 0.8125rem; color: var(--muted); }
.login-toggle a { color: var(--primary); font-weight: 700; cursor: pointer; }
.login-error { color: var(--danger); font-size: 0.8125rem; font-weight: 600; text-align: center; min-height: 1.25rem; margin-bottom: 0.5rem; }

/* ─── AI Assistant Widget ───────────────────────────────── */
.assistant-fab { position: fixed; bottom: 5rem; right: 1rem; background: var(--primary); color: #fff; border: none; border-radius: 9999px; padding: 1rem; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; z-index: 1000; }
.assistant-widget { position: fixed; bottom: 4.5rem; right: 1rem; left: 1rem; height: 60vh; background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius-lg); box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 1001; animation: slideUp 0.2s ease; }
.assistant-widget__header { padding: 1rem; background: var(--panel-strong); border-bottom: 1px solid var(--panel-border); display: flex; justify-content: space-between; font-weight: 700; }
.assistant-widget__body { flex: 1; padding: 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.assistant-widget__form { padding: 0.75rem; border-top: 1px solid var(--panel-border); display: flex; gap: 0.5rem; }

.chat-msg { max-width: 90%; display: flex; }
.chat-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg--bot { align-self: flex-start; }
.chat-msg__bubble { padding: 0.75rem 1rem; border-radius: var(--radius-md); font-size: 0.875rem; }
.chat-msg--user .chat-msg__bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 0.25rem;}
.chat-msg--bot .chat-msg__bubble { background: var(--panel-strong); border: 1px solid var(--panel-border); border-bottom-left-radius: 0.25rem; }

/* Markdown in chat */
.chat-msg__bubble p { margin-bottom: 0.5rem; }
.chat-msg__bubble p:last-child { margin-bottom: 0; }
.chat-msg__bubble ul, .chat-msg__bubble ol { margin-left: 1.25rem; margin-bottom: 0.5rem; }
.chat-msg__bubble table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; font-size: 0.8125rem; }
.chat-msg__bubble th, .chat-msg__bubble td { border: 1px solid var(--panel-border); padding: 0.35rem 0.5rem; text-align: left; }

.typing-indicator { display: flex; gap: 0.35rem; padding: 0.25rem 0.1rem; }
.typing-indicator span { width: 0.4rem; height: 0.4rem; background: var(--muted); border-radius: 50%; animation: typing 1.4s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

/* ─── Status Banner ─────────────────────────────────────── */
.status-banner { position: fixed; top: 1rem; left: 1rem; right: 1rem; z-index: 9999; padding: 0.75rem 1rem; border-radius: var(--radius-md); background: var(--panel-strong); border: 1px solid var(--panel-border); color: var(--text); font-weight: 600; text-align: center; box-shadow: var(--shadow); transition: opacity 0.3s; }
.status-banner--success { border-color: var(--success); color: var(--success); }
.status-banner--error { border-color: var(--danger); color: var(--danger); }
.status-banner--hidden { opacity: 0; pointer-events: none; }

.tab-content { display: none; }
.tab-content--active { display: block; animation: fadeUp 0.3s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(40px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ─── DESKTOP ENHANCEMENTS (min-width: 48rem / 768px) ───── */
@media (min-width: 48rem) {
  .page-shell { padding: 1.5rem 1.5rem 3rem; max-width: 78rem; }
  
  /* Topbar & Nav */
  .topbar { padding: 0.75rem 1.5rem; }
  .topbar__nav { display: flex; gap: 0.5rem; }
  .topbar__user { display: block; }
  .mobile-bottom-nav { display: none !important; }
  
  .topbar__nav button { padding: 0.5rem 0.75rem; background: transparent; border: none; color: var(--muted); font-weight: 600; border-radius: var(--radius-sm); cursor: pointer; }
  .topbar__nav button:hover { background: var(--glass); color: var(--text); }
  .topbar__nav button.tab-bar__btn--active { background: var(--glass); color: var(--primary); }

  /* Grids */
  .layout-grid--2 { grid-template-columns: repeat(2, 1fr); }
  .layout-grid--wide { grid-template-columns: 2fr 1fr; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
  
  /* Panels */
  .panel { padding: 1.5rem; }
  .panel__header { flex-direction: row; justify-content: space-between; align-items: flex-start; }
  .search-box { min-width: 16rem; }
  
  /* Table */
  table { display: table; border-collapse: collapse; width: 100%; }
  thead { display: table-header-group; }
  tbody { display: table-row-group; }
  tr { display: table-row; background: transparent; border: none; padding: 0; }
  th, td { display: table-cell; padding: 0.75rem; border-bottom: 1px solid var(--panel-border); text-align: left; }
  td::before { content: none; }
  .product-cell { text-align: left; }
  
  .action-buttons { flex-direction: row; margin-top: 0; width: auto; }
  td[data-label="Action"] { display: table-cell; padding-top: 0.75rem; border-top: none; margin-top: 0; }
  
  /* Stack Cards */
  .stack-card__row { flex-direction: row; align-items: flex-start; justify-content: space-between; }
  .stack-card .amount { align-self: auto; }
  .request-card__header { flex-direction: row; justify-content: space-between; align-items: center; }
  .request-card__actions { width: auto; margin-top: 0; }
  .user-card { flex-direction: row; justify-content: space-between; align-items: center; }
  
  /* Assistant Widget */
  .assistant-fab { bottom: 2rem; right: 2rem; padding: 1rem 1.5rem; }
  .assistant-widget { top: auto; bottom: 2rem; right: 2rem; left: auto; width: 380px; height: 600px; }
  
  /* Inputs */
  input, select, textarea { min-height: 2.5rem; font-size: 0.875rem; }
  .btn { min-height: 2.5rem; font-size: 0.8125rem; }
  
  /* Login */
  .login-card { padding: 2.5rem 2rem; }
}
