/* 
 * KatoInv Design System - Core Tokens & Utilities
 */

:root {
    /* Color Palette - Premium Slate & Electric Violet */
    --primary: #6366f1; /* Electric Indigo */
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    
    --accent: #f43f5e; /* Rose */
    
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --border: #e2e8f0;
    
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    /* Shadows & Effects */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-main);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--primary-hover);
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.23);
}

.btn-primary:disabled {
    background-color: var(--text-light);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--bg-surface-hover);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
    text-align: left;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--text-main);
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Layout Shell */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.sidebar-title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 0.25rem;
}

.nav-item:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-main);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.13), rgba(99,102,241,0.05));
    color: var(--primary);
    border-left: 3px solid var(--primary);
    padding-left: calc(1rem - 3px);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.25rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: 72px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.page-title {
    font-size: 1.25rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 36px;
    height: 36px;
    background-color: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.content-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Fullscreen Center (for Login) */
.fullscreen-center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background: var(--bg-surface);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-logo {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin: 0 auto 1.5rem;
}

.auth-logo .material-symbols-rounded {
    font-size: 28px;
}

/* Error Message */
.error-message {
    color: var(--error);
    font-size: 0.875rem;
    background-color: rgba(239, 68, 68, 0.1);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: none;
}

/* ================================================
   Dark Mode
   ================================================ */
body.dark {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #2d3f55;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #475569;
    --border: #334155;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 8px -1px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 12px 20px -3px rgb(0 0 0 / 0.5);
}

/* ================================================
   Page Fade-In Transition
   ================================================ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.page-fade-in {
    animation: fadeInUp 0.25s ease-out forwards;
}

/* ================================================
   Custom Scrollbar
   ================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ================================================
   KPI Cards
   ================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
/* ≤ 1500px – sidebar + 5 cards is too tight: drop to 4 */
@media (max-width: 1500px) {
    .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
/* ≤ 1200px – 3 columns */
@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* ≤ 800px – 2 columns */
@media (max-width: 800px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* ≤ 480px – 1 column */
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}
.kpi-card {
    background: var(--bg-surface);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform var(--transition), box-shadow var(--transition);
    min-width: 0; /* prevent grid blowout */
}
.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.kpi-icon .material-symbols-rounded { font-size: 1.3rem; }
.kpi-card.kpi-primary .kpi-icon { background: rgba(99,102,241,0.12); color: var(--primary); }
.kpi-card.kpi-success .kpi-icon { background: rgba(16,185,129,0.12); color: var(--success); }
.kpi-card.kpi-warning .kpi-icon { background: rgba(245,158,11,0.12); color: var(--warning); }
.kpi-card.kpi-accent  .kpi-icon { background: rgba(244,63,94,0.12);  color: var(--accent); }
.kpi-card.kpi-margin  .kpi-icon { background: rgba(20,184,166,0.12); color: #14b8a6; }

/* KPI loading pulse */
@keyframes kpiPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.kpi-loading { animation: kpiPulse 1s ease-in-out infinite; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-value {
    font-size: 1.7rem;
    font-weight: 800;
    font-family: var(--font-heading);
    color: var(--text-main);
    line-height: 1.1;
}
.kpi-trend {
    font-size: 0.72rem;
    font-weight: 600;
    margin-top: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.2rem;
}
.trend-up   { color: var(--success); }
.trend-down { color: var(--error); }
.trend-neutral { color: var(--text-muted); }
.kpi-trend .material-symbols-rounded { font-size: 0.9rem; }

/* ================================================
   Skeleton Loader
   ================================================ */
@keyframes shimmer {
    0%   { background-position: -600px 0; }
    100% { background-position:  600px 0; }
}
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-surface-hover) 25%,
        var(--border)           50%,
        var(--bg-surface-hover) 75%
    );
    background-size: 1200px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--radius-md);
}
.skeleton-kpi { height: 92px; border-radius: var(--radius-lg); }

/* ================================================
   Toast Notifications
   ================================================ */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    min-width: 280px;
    max-width: 380px;
    pointer-events: all;
    font-size: 0.875rem;
    font-weight: 500;
    animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes toastIn  { from { opacity:0; transform:translateX(80px); } to { opacity:1; transform:translateX(0); } }
@keyframes toastOut { from { opacity:1; transform:translateX(0);    } to { opacity:0; transform:translateX(80px); } }
.toast.removing { animation: toastOut 0.25s ease forwards; }
.toast-icon { font-size: 1.2rem; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--error); }
.toast-info    .toast-icon { color: var(--primary); }
.toast-warning .toast-icon { color: var(--warning); }

/* ================================================
   Badges / Pills
   ================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-error   { background: rgba(239,68,68,0.1);  color: var(--error); }

/* ================================================
   Topbar Improvements
   ================================================ */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    flex-shrink: 0;
}
.icon-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-main);
}
.icon-btn .material-symbols-rounded { font-size: 1.2rem; }
.notif-dot {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    border: 2px solid var(--bg-surface);
}
.user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
}

/* ================================================
   Chart Cards
   ================================================ */
.chart-card {
    background: var(--bg-surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition);
}
.chart-card:hover { box-shadow: var(--shadow-md); }
.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.chart-card-header h3 { margin-bottom: 0; }
.chart-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}
.chart-card h3 .material-symbols-rounded { font-size: 1.1rem; color: var(--text-muted); }

/* ================================================
   Granularity Toggle
   ================================================ */
.gran-toggle {
    display: inline-flex;
    background: var(--bg-surface-hover);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}
.gran-btn {
    padding: 0.25rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-body);
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.gran-btn:hover { color: var(--text-main); }
.gran-btn.active {
    background: var(--bg-surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    font-weight: 700;
}

/* ================================================
   Date Preset Buttons
   ================================================ */
.preset-group {
    display: inline-flex;
    background: var(--bg-surface-hover);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}
.preset-btn {
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: var(--font-body);
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.preset-btn:hover { color: var(--text-main); }
.preset-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

/* ================================================
   Sidebar Nav Labels
   ================================================ */
.nav-section-label {
    font-size: 0.67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-light);
    padding: 0 1rem;
    margin: 1.25rem 0 0.4rem;
    display: block;
}

/* ================================================
   Dashboard Filter Bar
   ================================================ */
.dash-filter-bar {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    gap: 0.75rem;
}
.dash-filter-bar > p { margin: 0; }

/* Row 1: location + dates + refresh */
.dash-filter-row1 {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
}
/* Row 2: preset pills */
.dash-filter-row2 {
    display: flex;
    gap: 0;
    align-items: center;
}

.dash-filter-controls {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    align-items: flex-start;
    width: 100%;
}

#dash_location {
    max-width: 180px;
    min-width: 140px;
}
.dash-filter-bar input[type="date"] {
    width: 140px;
}
.dash-filter-bar select,
.dash-filter-bar input[type="date"] {
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
    height: 36px;
    width: auto;
}

/* ================================================
   Responsive chart grids
   ================================================ */
@media (max-width: 1100px) {
    /* Main chart row: stack vertically */
    [style*="grid-template-columns: 2fr 1fr"] {
        display: block !important;
    }
    [style*="grid-template-columns: 2fr 1fr"] > * {
        margin-bottom: 1.5rem;
    }
    /* Secondary 3-col row: 2 cols */
    [style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }
}
@media (max-width: 700px) {
    [style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}
