/* ===== Design tokens ===== */
:root {
    --bg: #f6f3ec;
    --sidebar-bg: #16140f;
    --sidebar-bg-active: #2a2620;
    --sidebar-text: #d8d3c8;
    --sidebar-text-dim: #8c8579;
    --card-bg: #ffffff;
    --border: #e6e1d6;
    --text: #201d18;
    --text-muted: #706a5e;
    --blue: #2f6fed;
    --blue-bg: #e8f0fe;
    --green: #1a9c5a;
    --green-bg: #e5f6ec;
    --amber: #d97e15;
    --amber-bg: #fdf1de;
    --red: #e0393e;
    --red-bg: #fde9e9;
    --orange: #ea580c;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 18, 14, 0.05), 0 1px 8px rgba(20, 18, 14, 0.04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; flex-shrink: 0; }

/* ===== Auth page ===== */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.auth-card {
    width: 380px;
    max-width: calc(100vw - 40px);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 28px;
    text-align: center;
}
.auth-logo { display: flex; align-items: center; justify-content: center; margin-bottom: 18px; }
.auth-logo .logo-full { width: 220px; max-width: 100%; height: auto; }
.auth-title { font-size: 18px; margin: 4px 0 4px; }
.auth-tagline { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
.auth-form { text-align: left; display: flex; flex-direction: column; gap: 4px; }
.auth-error {
    background: var(--red-bg); color: var(--red); border: 1px solid #f3c6c7;
    border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 16px;
}
.auth-footnote { color: var(--text-muted); font-size: 12px; margin-top: 18px; }

.logo-full { display: block; height: auto; }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}
.sidebar-logo {
    display: flex; align-items: center; gap: 10px; flex-shrink: 0;
    padding: 6px 10px; margin-bottom: 18px;
}
.sidebar-logo-icon { width: 36px; height: 36px; border-radius: 9px; flex-shrink: 0; display: block; }
.sidebar-logo-text { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.01em; }
.sidebar-nav { display: flex; flex-direction: column; gap: 16px; }
.nav-section-label {
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em;
    color: var(--sidebar-text-dim); padding: 0 10px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 8px; font-size: 13.5px;
    color: var(--sidebar-text); margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-bg-active); color: #fff; }
.nav-item.active { background: #fff; color: #16140f; font-weight: 600; }
.nav-item .nav-icon { width: 16px; height: 16px; }

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

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--border);
    gap: 20px;
}
.topbar-search {
    flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 12px; color: var(--text-muted);
}
.topbar-search input {
    border: none; background: transparent; outline: none; flex: 1; font-size: 13.5px; color: var(--text);
}
.topbar-search-icon { width: 16px; height: 16px; }
.topbar-search kbd {
    font-size: 11px; background: #fff; border: 1px solid var(--border);
    border-radius: 4px; padding: 1px 6px; color: var(--text-muted);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
    background: #fff; display: flex; align-items: center; justify-content: center; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn .icon { width: 16px; height: 16px; }

.user-menu { position: relative; }
.user-menu-btn {
    display: flex; align-items: center; gap: 8px; border: none; background: transparent;
    padding: 4px 6px; border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--text);
}
.user-menu-btn:hover { background: var(--bg); }
.avatar {
    width: 26px; height: 26px; border-radius: 50%; background: var(--bg);
    display: flex; align-items: center; justify-content: center; color: var(--text-muted);
}
.avatar .icon { width: 14px; height: 14px; }
.dropdown {
    display: none; position: absolute; right: 0; top: 42px; background: #fff;
    border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
    min-width: 160px; padding: 6px; z-index: 40;
}
.dropdown.open { display: block; }
.dropdown a { display: block; padding: 8px 10px; border-radius: 6px; font-size: 13.5px; }
.dropdown a:hover { background: var(--bg); }

.page { padding: 28px 32px 60px; max-width: 1400px; }

.flash-msg {
    background: var(--green-bg); color: var(--green); border: 1px solid #bfe6cf;
    border-radius: 8px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 18px;
}

.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.page-header h1 { font-size: 24px; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 13.5px; }
.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
    border: 1px solid var(--border); background: #fff; color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn .icon { width: 15px; height: 15px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #2a63d6; }
.btn-orange { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-orange:hover { background: #d24f09; }
.btn-block { width: 100%; justify-content: center; margin-top: 14px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-danger { color: var(--red); border-color: #f3c6c7; }
.btn-danger:hover { background: var(--red-bg); }

/* ===== Stat cards ===== */
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 20px;
}
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border); border-left: 4px solid var(--border);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-card.blue { border-left-color: var(--blue); background: #f6f9ff; }
.stat-card.green { border-left-color: var(--green); background: #f3fbf6; }
.stat-card.amber { border-left-color: var(--amber); background: #fffaf1; }
.stat-card.red { border-left-color: var(--red); background: #fef6f6; }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: var(--text-muted); font-size: 13px; }
.stat-card-top .icon { width: 17px; height: 17px; }
.stat-card-top .icon.blue-ic { color: var(--blue); }
.stat-card-top .icon.green-ic { color: var(--green); }
.stat-card-top .icon.amber-ic { color: var(--amber); }
.stat-card-top .icon.red-ic { color: var(--red); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ===== Panels / cards ===== */
.panel {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-header h2 { font-size: 15px; margin: 0; }
.panel-header a, .panel-link { color: var(--blue); font-size: 13px; }
.panel-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 900px) { .panel-grid-2, .panel-grid-3 { grid-template-columns: 1fr; } }

.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 6px; }
.empty-state { color: var(--text-muted); font-size: 13px; padding: 10px 0; }

.activity-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.activity-row:last-child { border-bottom: none; }
.activity-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--text-muted); flex-shrink: 0; }
.activity-icon .icon { width: 15px; height: 15px; }
.activity-main { flex: 1; min-width: 0; }
.activity-title { font-size: 13.5px; font-weight: 500; }
.activity-meta { font-size: 12px; color: var(--text-muted); }
.activity-qty { font-size: 13px; font-weight: 600; }
.activity-qty.in { color: var(--green); }
.activity-qty.out { color: var(--red); }

/* ===== Tabs ===== */
.tabs { display: inline-flex; background: var(--bg); border-radius: 8px; padding: 3px; margin-bottom: 16px; gap: 2px; }
.tab {
    padding: 7px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); border: none; background: transparent;
}
.tab.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ===== Filter bar ===== */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filter-bar form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; width: 100%; }
.field-select, .field-input, .field-textarea {
    border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13.5px;
    background: #fff; color: var(--text); font-family: inherit;
}
.field-input:focus, .field-select:focus, .field-textarea:focus { outline: 2px solid #cddafb; border-color: var(--blue); }
.search-input { min-width: 220px; }
.field-textarea { resize: vertical; width: 100%; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
table.data-table th {
    text-align: left; padding: 11px 16px; color: var(--text-muted); font-weight: 600; font-size: 12px;
    text-transform: none; border-bottom: 1px solid var(--border); background: #fbfaf7; white-space: nowrap;
}
table.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr.clickable:hover { background: #fbfaf7; cursor: pointer; }
.cell-title { font-weight: 500; }
.cell-sub { font-size: 12px; color: var(--text-muted); }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.row-actions { display: flex; justify-content: flex-end; }

/* ===== Badges ===== */
.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: #eeece5; color: var(--text-muted); }
.badge-btn { border: none; cursor: pointer; font-family: inherit; }
.field-select-sm { padding: 4px 8px; font-size: 12px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }

/* ===== Modal / Drawer ===== */
.overlay {
    display: none; position: fixed; inset: 0; background: rgba(20, 18, 14, 0.42); z-index: 100;
    align-items: center; justify-content: center;
}
.overlay.open { display: flex; }
.overlay.drawer-overlay { justify-content: flex-end; }

.modal {
    background: #fff; border-radius: 12px; width: 460px; max-width: calc(100vw - 32px);
    max-height: calc(100vh - 60px); overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.drawer {
    background: #fff; width: 440px; max-width: calc(100vw - 32px); height: 100%;
    overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,0.15);
}
.modal-header, .drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 2;
}
.modal-header h2, .drawer-header h2 { font-size: 16px; margin: 0; }
.modal-header p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-muted); }
.modal-close { background: none; border: none; color: var(--text-muted); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); }
.modal-body, .drawer-body { padding: 20px 22px; }
.modal-footer, .drawer-footer {
    display: flex; gap: 10px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--border);
    position: sticky; bottom: 0; background: #fff;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group.full { grid-column: 1 / -1; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field-hint { font-size: 11.5px; color: var(--text-muted); }
.field-section-label {
    font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--text-muted);
    text-transform: uppercase; margin: 18px 0 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.field-section-label:first-child { border-top: none; margin-top: 0; padding-top: 0; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute; inset: 0; background: #ccc; border-radius: 999px; transition: 0.15s;
}
.switch-slider::before {
    content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff;
    border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .switch-slider { background: var(--blue); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }

.detail-image-placeholder {
    background: var(--bg); border: 1px dashed var(--border); border-radius: 10px; height: 140px;
    display: flex; align-items: center; justify-content: center; color: var(--text-muted); margin-bottom: 16px;
}
.detail-image-placeholder .icon { width: 34px; height: 34px; }
.detail-hero {
    background: var(--bg); border-radius: 10px; padding: 18px; text-align: center; margin-bottom: 18px;
}
.detail-hero-label { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; color: var(--text-muted); }
.detail-hero-value { font-size: 30px; font-weight: 700; color: var(--green); margin: 4px 0 2px; }
.detail-hero-unit { font-size: 12px; color: var(--text-muted); }
.detail-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-field-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 3px; }
.detail-field-value { font-size: 13.5px; font-weight: 500; }
.detail-status-row { display: flex; gap: 8px; margin-bottom: 16px; }

/* ===== Donut chart ===== */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.donut {
    width: 170px; height: 170px; border-radius: 50%; position: relative;
    display: flex; align-items: center; justify-content: center;
}
.donut-center { font-size: 22px; font-weight: 700; }
.donut-legend { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; font-size: 12.5px; }
.donut-legend span.sw { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* ===== AI insight cards ===== */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.insight-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: #fff; }
.insight-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.insight-card-name { font-weight: 600; font-size: 14px; }
.insight-card-sku { font-size: 12px; color: var(--text-muted); }
.insight-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; color: var(--text-muted); }
.insight-row b { color: var(--text); font-weight: 600; }
.insight-actions { display: flex; gap: 8px; margin-top: 12px; }
.insight-actions .btn { flex: 1; justify-content: center; }

/* ===== Empty svg chart placeholder ===== */
.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { display: block; }

.checkbox-cell { width: 34px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ===== Trend chart (line + area) ===== */
.chart-trend { position: relative; width: 100%; height: 220px; }
.chart-trend-svg { width: 100%; height: 220px; display: block; overflow: visible; }
.chart-axis { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke: var(--blue); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--blue); opacity: 0.1; stroke: none; }
.chart-crosshair {
    position: absolute; top: 0; bottom: 20px; width: 1px; background: var(--border);
    pointer-events: none;
}
.chart-tooltip {
    position: absolute; top: 6px; pointer-events: none; background: #201d18; color: #fff;
    border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); z-index: 5;
    min-width: 100px;
}
.chart-tooltip-date { color: #c9c4b8; font-size: 11px; margin-bottom: 2px; }
.chart-tooltip-qty { font-weight: 600; }
.chart-trend-axis { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ===== Horizontal bar chart ===== */
.chart-bars { display: flex; flex-direction: column; gap: 10px; }
.chart-bar-row { display: grid; grid-template-columns: 160px 1fr 44px; align-items: center; gap: 10px; }
.chart-bar-label { font-size: 12.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-bar-track { background: var(--bg); border-radius: 4px; height: 20px; overflow: hidden; }
.chart-bar-fill { background: var(--blue); height: 100%; border-radius: 0 4px 4px 0; min-width: 4px; transition: width 0.2s ease; }
.chart-bar-value { font-size: 12.5px; font-weight: 600; text-align: right; color: var(--text); }
@media (max-width: 700px) { .chart-bar-row { grid-template-columns: 100px 1fr 36px; } .chart-bar-label { font-size: 11.5px; } }

/* ===== AI Assistant chat ===== */
.ai-chat { display: flex; flex-direction: column; gap: 14px; }
.ai-chat-messages {
    display: flex; flex-direction: column; gap: 10px;
    min-height: 240px; max-height: 480px; overflow-y: auto; padding: 4px 2px;
}
.ai-chat-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    flex: 1; padding: 40px 20px; color: var(--text-muted); text-align: center;
}
.ai-chat-empty .icon { width: 28px; height: 28px; }
.ai-message {
    max-width: 72%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px;
    line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
}
.ai-message.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.ai-message.assistant {
    align-self: flex-start; background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.ai-message.assistant.typing { color: var(--text-muted); font-style: italic; }
.ai-message.assistant.error { background: var(--red-bg); color: var(--red); border-color: #f3c6c7; }

.ai-suggested-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    border: 1px solid var(--border); background: #fff; border-radius: 999px;
    padding: 6px 12px; font-size: 12.5px; color: var(--text); font-family: inherit;
}
.chip:hover { background: var(--bg); }

.ai-chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.ai-chat-input-row .field-textarea { flex: 1; min-height: 44px; max-height: 140px; }
.ai-chat-input-row .btn { flex-shrink: 0; }
@media (max-width: 700px) { .ai-message { max-width: 88%; } }
