/* =========================================================
   KapokHub ERP — iOS 26 "Liquid Glass" design tokens
   ========================================================= */
:root {
    --bg: #E8EBF0;
    --bg-grad: linear-gradient(180deg, #ECEEF3 0%, #E7EAEF 100%);
    --glass: rgba(255, 255, 255, 0.9);
    --glass-strong: #FFFFFF;
    --glass-border: rgba(18, 22, 43, 0.06);
    --ink: #16202A;
    --ink-soft: #5B6472;
    --ink-faint: #9AA1AD;
    --accent: #1F9254;
    --accent-ink: #E6F4EC;
    --accent-2: #16733B;
    --success: #1E8E5A;
    --success-bg: #E4F5EC;
    --danger: #D1453B;
    --danger-bg: #FBE7E5;
    --warning: #C6862A;
    --warning-bg: #FBF0DF;
    --divider: rgba(18, 22, 43, 0.07);
    --shadow-sm: 0 1px 3px rgba(18, 22, 43, 0.05);
    --shadow-md: 0 6px 20px rgba(18, 22, 43, 0.07);
    --shadow-lg: 0 20px 50px rgba(18, 22, 43, 0.14);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --font-display: -apple-system, "SF Pro Display", "Segoe UI Semibold", Roboto, sans-serif;
    --font-body: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Menlo", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--bg-grad);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent); color: #fff; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

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

.sidebar {
    width: 248px;
    flex-shrink: 0;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}
.sidebar-brand { flex-shrink: 0; }
#navList {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(18,22,43,0.2) transparent;
}
#navList::-webkit-scrollbar { width: 6px; }
#navList::-webkit-scrollbar-thumb { background: rgba(18,22,43,0.18); border-radius: 3px; }
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 20px;
}
.sidebar-brand .logo-dot {
    width: 34px; height: 34px; border-radius: 11px;
    background: linear-gradient(145deg, var(--accent), #4A6BC4);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-family: var(--font-display);
    box-shadow: var(--shadow-sm);
}
.sidebar-brand .brand-text { font-family: var(--font-display); font-weight: 700; font-size: 15.5px; line-height: 1.15; }
.sidebar-brand .brand-sub { font-size: 11.5px; color: var(--ink-faint); }

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    font-weight: 500; font-size: 14.5px;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, transform .12s ease;
    user-select: none;
}
.nav-item:hover { background: rgba(18,22,43,0.045); color: var(--ink); }
.nav-item.active {
    background: var(--glass-strong);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(20px);
}
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; }
.nav-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); padding: 16px 14px 6px; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding: 10px 12px; flex-shrink: 0; }
.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; border-radius: var(--radius-sm);
    background: var(--glass); backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
}
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(145deg, var(--accent-2), #D6AE58);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--ink-faint); }
.logout-btn { background: none; border: none; color: var(--ink-faint); font-size: 16px; cursor: pointer; padding: 4px; }
.logout-btn:hover { color: var(--danger); }

/* ---------- Main content ---------- */
.main {
    flex: 1;
    min-width: 0;
    padding: 22px 26px 100px;
}
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px; gap: 12px;
}
.topbar h1 { font-family: var(--font-display); font-size: 22px; margin: 0; font-weight: 750; letter-spacing: -0.01em; }
.topbar .sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 2px; }
.hamburger { display: none; }

.guest-banner {
    background: var(--warning-bg); color: var(--warning);
    border-radius: var(--radius-sm); padding: 10px 14px;
    font-size: 13px; font-weight: 600; margin-bottom: 16px;
    display: flex; align-items: center; gap: 8px;
}

/* ---------- Glass card ---------- */
.card {
    background: var(--glass);
    backdrop-filter: blur(22px) saturate(1.4);
    -webkit-backdrop-filter: blur(22px) saturate(1.4);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 20px;
}
.card + .card { margin-top: 16px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat-card {
    background: var(--glass);
    backdrop-filter: blur(22px) saturate(1.4);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.5), transparent 55%);
    pointer-events: none;
}
.stat-card .label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.stat-card .value { font-family: var(--font-display); font-size: 25px; font-weight: 750; margin-top: 4px; letter-spacing: -0.01em; }
.stat-card .value .unit { font-size: 13px; color: var(--ink-faint); font-weight: 500; margin-left: 3px; }
.stat-card .delta { font-size: 12px; margin-top: 6px; font-weight: 600; }
.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--danger); }

.section-title { font-family: var(--font-display); font-weight: 700; font-size: 16px; margin: 0 0 12px; display:flex; align-items:center; gap:8px;}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: none; border-radius: 100px;
    padding: 10px 18px; font-weight: 650; font-size: 14px;
    cursor: pointer; transition: transform .1s ease, filter .15s ease, box-shadow .15s ease;
    white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(47,75,143,0.32); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: rgba(18,22,43,0.05); color: var(--ink); }
.btn-ghost:hover { background: rgba(18,22,43,0.09); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { filter: brightness(0.97); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 100px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 50%; background: rgba(18,22,43,0.05); color: var(--ink-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 11px 13px;
    border-radius: var(--radius-sm); border: 1px solid var(--divider);
    background: rgba(255,255,255,0.75);
    outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,75,143,0.14);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }
.field-inline-add { display: flex; gap: 6px; }
.field-inline-add select { flex: 1; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
    text-align: left; padding: 10px 12px; font-size: 11.5px; text-transform: uppercase;
    letter-spacing: .04em; color: var(--ink-faint); font-weight: 700;
    border-bottom: 1px solid var(--divider); white-space: nowrap;
}
table.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--divider); white-space: nowrap; }
table.data-table tbody tr { transition: background .12s; }
table.data-table tbody tr:hover { background: rgba(47,75,143,0.045); }
table.data-table tbody tr:last-child td { border-bottom: none; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 100px; font-size: 11.5px; font-weight: 700; }
.badge-blue { background: #E4ECFB; color: #2F5FBF; }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-gray { background: rgba(18,22,43,0.06); color: var(--ink-soft); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.search-box { position: relative; }
.search-box input { padding-left: 34px; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-faint); }
.empty-state .emoji { font-size: 38px; margin-bottom: 10px; }

.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 13px; color: var(--ink-soft); }

/* ---------- Modal / sheet ---------- */
.overlay {
    position: fixed; inset: 0; background: rgba(18,22,43,0.38);
    backdrop-filter: blur(4px);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 100; animation: fadein .18s ease;
}
@media (min-width: 720px) { .overlay { align-items: center; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.sheet {
    background: var(--glass-strong);
    backdrop-filter: blur(30px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: 28px 28px 0 0;
    width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
    padding: 22px 22px calc(22px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
    animation: slideup .22s cubic-bezier(.2,.9,.3,1);
}
@media (min-width: 720px) { .sheet { border-radius: var(--radius-lg); } }
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-header h2 { font-family: var(--font-display); font-size: 18px; margin: 0; }
.sheet-close { background: rgba(18,22,43,0.06); border: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 15px; color: var(--ink-soft); }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Media / upload ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.media-thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: rgba(18,22,43,0.06); }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .del-btn {
    position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
    background: rgba(18,22,43,0.6); color: #fff; border: none; font-size: 11px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.upload-drop {
    border: 1.5px dashed rgba(18,22,43,0.18); border-radius: var(--radius-md);
    padding: 18px; text-align: center; color: var(--ink-soft); font-size: 13px;
    cursor: pointer; transition: border-color .15s, background .15s;
}
.upload-drop:hover { border-color: var(--accent); background: rgba(47,75,143,0.04); }

/* ---------- Toast ---------- */
#toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--glass-strong); backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border); border-radius: var(--radius-sm);
    padding: 12px 16px; box-shadow: var(--shadow-md); font-size: 13.5px; font-weight: 600;
    animation: slidein .18s ease; max-width: 320px;
}
.toast.success { color: var(--success); }
.toast.error { color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity:0;} to { transform: translateX(0); opacity:1;} }

/* ---------- Bottom tab bar (mobile) ---------- */
.tabbar {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--glass-strong);
    backdrop-filter: blur(24px) saturate(1.6);
    border-top: 1px solid var(--glass-border);
}
.tabbar-inner { display: flex; justify-content: space-around; align-items: center; }
.tab-item { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink-faint); font-size: 10.5px; font-weight: 600; padding: 4px 10px; border-radius: 14px; transition: color .15s; }
.tab-item .icon { font-size: 19px; }
.tab-item.active { color: var(--accent); }

/* ---------- Loading ---------- */
.skeleton { background: linear-gradient(90deg, rgba(18,22,43,0.06) 25%, rgba(18,22,43,0.10) 37%, rgba(18,22,43,0.06) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 10px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; animation: spin .7s linear infinite; display:inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; z-index: 200; transform: translateX(-104%); transition: transform .25s cubic-bezier(.2,.9,.3,1); background: var(--glass-strong); backdrop-filter: blur(24px); width: 270px; }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-scrim { display: none; position: fixed; inset: 0; background: rgba(18,22,43,0.35); z-index: 190; }
    .sidebar-scrim.show { display: block; }
    .hamburger { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-border); cursor: pointer; font-size: 17px; }
    .main { padding: 16px 14px 90px; }
    .tabbar { display: block; }
    .field-row { grid-template-columns: 1fr; }
}
@media (min-width: 901px) {
    .tabbar { display: none; }
}
