/* SMS Energy - Shared Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@700;800&display=swap');

:root {
    --bg: #f3faff; --surface: #fff; --surface-alt: #e6f6ff; --border: #d5ecf8;
    --text: #071e27; --text-muted: #64748b; --text-subtle: #94a3b8;
    --primary: #004253; --secondary: #006b5e; --accent: #00d084;
    --error: #ba1a1a; --warning: #fcb900;
    --sidebar-bg: #f1f5f9; --sidebar-border: #e2e8f0; --sidebar-text: #475569;
    --sidebar-active-bg: #fff; --sidebar-brand: #004253;
    --table-header-bg: #f3faff; --table-hover: #f3faff;
    --topbar-bg: rgba(241,245,249,0.8);
}
[data-theme="dark"] {
    --bg: #0f1a21; --surface: #1a2a34; --surface-alt: #162028; --border: #2a3a44;
    --text: #e2ecf0; --text-muted: #8fa3b0; --text-subtle: #5a7080;
    --primary: #8dd0e9; --secondary: #7ad7c6; --accent: #00d084;
    --error: #ffb4ab; --warning: #fcb900;
    --sidebar-bg: #0d1820; --sidebar-border: #2a3a44; --sidebar-text: #8fa3b0;
    --sidebar-active-bg: #1a2a34; --sidebar-brand: #8dd0e9;
    --table-header-bg: #162028; --table-hover: #1a2a34;
    --topbar-bg: rgba(15,26,33,0.85);
}
[data-theme="sms"] {
    --bg: #f0fdf4; --surface: #fff; --surface-alt: #dcfce7; --border: #bbf7d0;
    --text: #052e16; --text-muted: #4d7c5f; --text-subtle: #86b89a;
    --primary: #15803d; --secondary: #166534; --accent: #4ade80;
    --error: #dc2626; --warning: #f59e0b;
    --sidebar-bg: #052e16; --sidebar-border: #166534; --sidebar-text: #bbf7d0;
    --sidebar-active-bg: #166534; --sidebar-brand: #fff;
    --table-header-bg: #f0fdf4; --table-hover: #dcfce7;
    --topbar-bg: rgba(240,253,244,0.85);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3, h4 { font-family: 'Manrope', sans-serif; }

/* Sidebar */
.sidebar { position: fixed; top: 0; left: 0; width: 220px; height: 100vh; background: var(--sidebar-bg); padding: 1.5rem 0; display: flex; flex-direction: column; border-right: 1px solid var(--sidebar-border); z-index: 50; }
.sidebar .brand { color: var(--sidebar-brand); font-size: 1.3rem; font-weight: 800; padding: 0 1.2rem 1.5rem; border-bottom: 1px solid var(--sidebar-border); font-family: 'Manrope', sans-serif; }
.sidebar nav { flex: 1; padding-top: 1rem; }
.sidebar nav a { display: block; color: var(--sidebar-text); padding: 0.7rem 1.2rem; text-decoration: none; font-size: 0.85rem; transition: all 0.2s; border-radius: 0.5rem; margin: 0.15rem 0.5rem; }
.sidebar nav a:hover, .sidebar nav a.active { background: var(--sidebar-active-bg); color: var(--sidebar-brand); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.sidebar .version { color: var(--text-subtle); font-size: 0.75rem; padding: 1rem 1.2rem; }
.sidebar-user { padding: 0.8rem 1.2rem; border-top: 1px solid var(--sidebar-border); }
.sidebar-user .user-name { font-size: 0.8rem; font-weight: 600; color: var(--sidebar-brand); }
.sidebar-user .user-role { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.1rem; }
.sidebar-user .logout-btn { margin-top: 0.5rem; font-size: 0.72rem; padding: 0.3rem 0.6rem; border: 1px solid var(--sidebar-border); border-radius: 0.3rem; background: var(--sidebar-bg); color: var(--sidebar-text); cursor: pointer; }
.sidebar-user .logout-btn:hover { background: var(--surface); color: var(--primary); }

/* Jobs section in sidebar */
.jobs-section { padding: 0.8rem 1.2rem; border-top: 1px solid var(--sidebar-border); }
.jobs-section h3 { color: var(--sidebar-brand); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.5rem; font-weight: 600; }
.jobs-section ul { list-style: none; padding: 0; }
.jobs-section li { margin-bottom: 0.3rem; }
.jobs-section a { color: var(--sidebar-text); text-decoration: none; font-size: 0.75rem; display: flex; justify-content: space-between; padding: 0.3rem 0; }
.jobs-section a:hover { color: var(--sidebar-brand); }

/* Job status badges */
.job-status { font-size: 0.65rem; padding: 0.15rem 0.5rem; border-radius: 4px; font-weight: 600; }
.job-status.PROCESSING { background: #fef3c7; color: #92400e; }
.job-status.COMPLETED { background: #d1fae5; color: #065f46; }
.job-status.FAILED { background: #fee2e2; color: #991b1b; }
.job-status.QUEUED { background: #e2e8f0; color: #475569; }

/* Main content area */
.main { margin-left: 220px; padding: 2rem; min-height: 100vh; }

/* Page headings */
h1 { color: var(--primary); margin-bottom: 1.5rem; font-size: 1.5rem; font-weight: 800; }
h2 { color: var(--primary); font-size: 1.1rem; font-weight: 700; margin-bottom: 0.8rem; }

/* Top bar (dashboard) */
.topbar { background: var(--topbar-bg); backdrop-filter: blur(12px); padding: 0.8rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1.5rem; position: sticky; top: 0; z-index: 40; }
.topbar .filters { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.topbar label { font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 0.3rem; color: var(--text-muted); }
.topbar .stats { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

/* Buttons */
.btn { background: var(--secondary); color: #fff; border: none; padding: 0.6rem 1.2rem; border-radius: 0.5rem; cursor: pointer; font-size: 0.85rem; font-weight: 500; transition: all 0.2s; }
.btn:hover { background: var(--primary); }
.btn:disabled { background: var(--text-subtle); cursor: not-allowed; }
.btn-danger { background: var(--error); color: #fff; border: none; padding: 0.5rem 1.2rem; border-radius: 0.5rem; cursor: pointer; font-size: 0.85rem; font-weight: 500; }
.btn-danger:hover { background: #7f1d1d; }

/* Cards */
.card { background: var(--surface); border-radius: 0.75rem; padding: 1.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border); }

/* Metric cards */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.metric-card { background: var(--surface); border-radius: 0.75rem; padding: 1.2rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border); }
.metric-card .label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.3rem; font-weight: 600; }
.metric-card .value { font-size: 1.6rem; font-weight: 800; color: var(--primary); font-family: 'Manrope', sans-serif; }
.metric-card .sub { font-size: 0.72rem; color: var(--text-subtle); margin-top: 0.2rem; }

/* Charts */
.charts { display: flex; gap: 1.5rem; margin-bottom: 2rem; flex-wrap: wrap; }
.chart-box { background: var(--surface); border-radius: 0.75rem; padding: 1.2rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border); flex: 1; min-width: 280px; text-align: center; }
.chart-box h3 { font-size: 0.8rem; color: var(--primary); margin-bottom: 0.5rem; font-weight: 700; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; background: var(--surface); border-radius: 0.5rem; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--table-header-bg); color: var(--primary); font-weight: 600; position: sticky; top: 0; border-bottom: 2px solid var(--secondary); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.3px; }
tr:hover { background: var(--table-hover); }
.meter-row { background: var(--surface-alt); }
.meter-row td { padding: 0.4rem 0.6rem 0.4rem 2rem; }
button.expand-btn { border: 1px solid var(--secondary); background: var(--surface); color: var(--secondary); border-radius: 6px; width: 22px; height: 22px; cursor: pointer; font-size: 0.75rem; transition: all 0.2s; }
button.expand-btn:hover { background: var(--secondary); color: #fff; }

/* Status badges */
.status-badge { padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.7rem; font-weight: 600; }
.status-badge.critical { background: #fee2e2; color: #991b1b; }
.status-badge.warning { background: #fef3c7; color: #92400e; }
.status-badge.info { background: #dbeafe; color: #1e40af; }
.status-badge.transit { background: #fef3c7; color: #92400e; }
.status-badge.warehouse { background: #dbeafe; color: #1e40af; }
.status-badge.map { background: #d1fae5; color: #065f46; }

/* Upload card */
.upload-card { background: var(--surface); border-radius: 0.75rem; padding: 1.5rem; max-width: 500px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border); }
.upload-card input[type="file"] { margin-bottom: 1rem; }
.upload-card button { background: var(--secondary); color: #fff; border: none; padding: 0.6rem 1.5rem; border-radius: 0.5rem; cursor: pointer; font-size: 0.85rem; font-weight: 500; }
.upload-card button:hover { background: var(--primary); }
.upload-card p { color: var(--text-muted); font-size: 0.82rem; margin-top: 1rem; line-height: 1.5; }

/* Jobs table */
.jobs-table { width: 100%; max-width: 800px; border-collapse: collapse; font-size: 0.82rem; margin-top: 0.5rem; background: var(--surface); border-radius: 0.75rem; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border); }
.jobs-table th, .jobs-table td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); }
.jobs-table th { background: var(--table-header-bg); color: var(--primary); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.3px; }
.jobs-table a { color: var(--secondary); font-weight: 500; text-decoration: none; }
.jobs-table a:hover { text-decoration: underline; }

/* Chat / AI Agent */
.chat-container { flex: 1; display: flex; flex-direction: column; max-width: 800px; width: 100%; }
.messages { flex: 1; overflow-y: auto; background: var(--surface); border-radius: 0.75rem; padding: 1.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border); margin-bottom: 1rem; min-height: 400px; max-height: 60vh; }
.message { margin-bottom: 1rem; padding: 0.8rem 1rem; border-radius: 0.75rem; max-width: 85%; line-height: 1.5; font-size: 0.88rem; }
.message.user { background: var(--secondary); color: #fff; margin-left: auto; }
.message.assistant { background: var(--surface-alt); color: var(--text); }
.message.assistant pre { background: var(--border); padding: 0.5rem; border-radius: 0.5rem; overflow-x: auto; font-size: 0.78rem; margin: 0.5rem 0; }
.input-area { display: flex; gap: 0.5rem; }
.input-area input { flex: 1; padding: 0.8rem 1rem; border: 2px solid var(--border); border-radius: 0.75rem; font-size: 0.88rem; outline: none; transition: border-color 0.2s; font-family: 'Inter', sans-serif; background: var(--surface); color: var(--text); }
.input-area input:focus { border-color: var(--secondary); }
.input-area button { background: var(--secondary); color: #fff; border: none; padding: 0.8rem 1.5rem; border-radius: 0.75rem; cursor: pointer; font-size: 0.88rem; font-weight: 600; }
.input-area button:hover { background: var(--primary); }
.input-area button:disabled { background: var(--text-subtle); cursor: not-allowed; }
.typing { color: var(--text-subtle); font-style: italic; font-size: 0.82rem; padding: 0.5rem 0; }

/* Dashboard-specific panels */
.dashboard { display: flex; flex-direction: column; height: calc(100vh - 52px); }
.panel { background: var(--surface-alt); padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.panel h2 { color: var(--primary); font-size: 0.95rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.panel h2 .label, h2 .label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--secondary); font-weight: 600; font-family: 'Inter', sans-serif; }
.panel-toggle { font-size: 0.75rem; color: var(--text-muted); margin-left: 0.5rem; }

/* Risk panel */
.risk-panel { background: var(--surface-alt); }
#riskChartContent { background: var(--surface); border-radius: 0.75rem; margin-top: 0.8rem; padding: 1rem; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }

/* Chart tiles */
.chart-panel { background: var(--bg); }
.chart-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; padding: 0.8rem 0 0; }
.chart-tile { background: var(--surface); border-radius: 0.75rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); padding: 1.2rem 1rem 1rem; display: flex; flex-direction: column; align-items: center; transition: all 0.2s; border: 1px solid var(--border); }
.chart-tile:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); transform: translateY(-2px); }
.chart-tile h3 { font-size: 0.8rem; color: var(--primary); margin: 0 0 0.15rem; font-weight: 700; }
.chart-tile p { font-size: 0.68rem; color: var(--text-muted); text-align: center; margin: 0 0 0.6rem; line-height: 1.4; }

/* Map */
#map { width: 100%; height: 100%; }
.map-panel { position: relative; border-bottom: 1px solid var(--border); flex: 1; min-height: 300px; }
.legend { background: var(--surface); padding: 0.6rem 1rem; border-radius: 0.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.1); line-height: 1.8; font-size: 0.75rem; font-family: 'Inter', sans-serif; }
.legend i { width: 10px; height: 10px; display: inline-block; border-radius: 50%; margin-right: 6px; }

/* Table panel */
.table-panel { overflow: auto; padding: 1rem 1.5rem; background: var(--surface); flex-shrink: 0; }
.table-panel h2 { color: var(--primary); font-size: 0.95rem; margin-bottom: 0.8rem; font-weight: 700; }

/* Links */
a { color: var(--secondary); text-decoration: none; }
a:hover { color: var(--primary); text-decoration: underline; }

/* Status text */
.status { font-size: 0.82rem; color: var(--text-muted); }
.empty { color: var(--text-subtle); font-style: italic; padding: 2rem; text-align: center; }

/* Legacy page support (index, job, map, details) */
.legacy-page { max-width: 100%; margin: 0 auto; padding: 0 1rem; }
.legacy-page .header-bar { background: var(--primary); color: #fff; padding: 1rem 1.5rem; margin: 0 -1rem 2rem -1rem; border-radius: 0; }
.legacy-page .header-bar h1 { color: #fff; margin: 0; font-size: 1.3rem; }
.legacy-page .header-bar a { color: var(--border); }

/* Theme toggle */
.theme-toggle { padding: 0.8rem 1.2rem; border-top: 1px solid var(--sidebar-border); }
.theme-toggle-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 600; display: block; margin-bottom: 0.4rem; }
.theme-toggle-btns { display: flex; gap: 0.3rem; }
.theme-toggle-btns button { width: 32px; height: 28px; border: 1px solid var(--border); background: var(--surface); border-radius: 0.4rem; cursor: pointer; font-size: 0.85rem; transition: all 0.2s; }
.theme-toggle-btns button:hover { background: var(--sidebar-active-bg); border-color: var(--secondary); }

/* Responsive */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .main { margin-left: 0; }
    .chart-tiles { grid-template-columns: repeat(2, 1fr); }
}
