/* ============================================================
   EVcharge Server — Shared Styles
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
    --dark: #1B0E5A;
    --orange: #F4790F;
    --orange-hover: #e06a00;
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #22c55e;
    --error: #ef4444;
    --pending: #f59e0b;
    --radius: 8px;
}

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

/* ── Base ───────────────────────────────────────────────────── */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

h1 { font-size: 1.5rem; color: var(--dark); margin-bottom: 1rem; }

/* ── Navbar ─────────────────────────────────────────────────── */
.navbar {
    background: var(--dark);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand { color: white; font-size: 1.2rem; font-weight: 700; }
.nav-logo  { font-size: 1.4rem; }
.nav-links { display: flex; gap: 0.5rem; align-items: center; }
.nav-link {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: all 0.2s;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}
.nav-link:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-logout { color: rgba(255,255,255,0.6); }

/* ── Layout ─────────────────────────────────────────────────── */
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    background: var(--dark);
    color: white;
}
.btn:hover { opacity: 0.9; }

.btn-primary { background: var(--orange); color: white; border-color: var(--orange); }
.btn-primary:hover { background: var(--orange-hover); border-color: var(--orange-hover); }

.btn-outline { background: transparent; color: var(--dark); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }

.btn-danger { background: var(--error); color: white; border-color: var(--error); }

.btn-sm    { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.btn-lg    { padding: 0.9rem 2rem; font-size: 1.1rem; min-height: 48px; }
.btn-block { width: 100%; justify-content: center; }

/* Pagination link (standalone, no .btn base) */
.btn-page {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
}
.btn-page:hover { border-color: var(--orange); color: var(--orange); }

/* Action buttons (calculate page) */
.btn-apply {
    background: var(--dark); color: white; border: none;
    padding: 0.9rem 1.5rem; border-radius: var(--radius);
    font-size: 1rem; font-weight: 600; cursor: pointer; min-height: 48px; font-family: inherit;
}
.btn-apply:hover { background: #2a1a7a; }

.btn-recalc {
    background: #d97706; color: white; border: none;
    padding: 0.9rem 1.5rem; border-radius: var(--radius);
    font-size: 1rem; font-weight: 600; cursor: pointer; min-height: 48px; font-family: inherit;
}
.btn-recalc:hover { background: #b45309; }

.btn-revert {
    background: #dc2626; color: white; border: none;
    padding: 0.7rem 1.5rem; border-radius: var(--radius);
    font-size: 1rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-revert:hover { background: #b91c1c; }

.btn-search {
    padding: 0.55rem 1.2rem; background: var(--orange); color: white; border: none;
    border-radius: var(--radius); font-weight: 600; cursor: pointer; font-size: 0.95rem; font-family: inherit;
}
.btn-search:hover { background: var(--orange-hover); }

.btn-clear { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; font-weight: 500; }
.btn-clear:hover { color: var(--orange); }

/* ── Forms ──────────────────────────────────────────────────── */
.form-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.5rem;
    max-width: 500px;
}

.calc-form {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.9rem; color: var(--text-muted); }
.form-group input,
.form-input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: white;
    -webkit-appearance: none;
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-input:focus {
    outline: none;
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(244,121,15,0.1);
}

.form-hint { display: block; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.form-actions,
.form-buttons { display: flex; gap: 0.75rem; margin-top: 1rem; }
.form-buttons .btn,
.form-buttons .btn-apply,
.form-buttons .btn-revert { flex: 1; }

.input-row { display: flex; gap: 0.5rem; }
.input-row .form-input:first-child,
.input-row .form-group:first-child input { flex: 1; }
.markup-type { width: 80px; flex-shrink: 0; }

.calc-divider { margin: 2rem 0; border: none; border-top: 1px solid var(--border); }

.settings-form { max-width: 600px; }
.settings-form h3 { margin-top: 1.5rem; margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.settings-group { background: var(--card-bg); padding: 1.25rem; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 1rem; display: flex; flex-direction: column; gap: 1rem; }

.retry-row  { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.retry-num  { width: 64px !important; text-align: center; padding: 0.5rem 0.4rem !important; }
.retry-label { font-size: 0.9rem; color: var(--text-muted); white-space: nowrap; }

/* ── Toggle Switch ──────────────────────────────────────────── */
.toggle-label { display: flex !important; align-items: center; justify-content: space-between; cursor: pointer; font-weight: 600; font-size: 0.9rem; user-select: none; margin-bottom: 0; }
.toggle-wrap { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-wrap input[type="checkbox"] { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: background 0.2s; cursor: pointer; }
.toggle-slider::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: white; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.toggle-wrap input[type="checkbox"]:checked + .toggle-slider { background: var(--orange); }
.toggle-wrap input[type="checkbox"]:checked + .toggle-slider::after { transform: translateX(20px); }

/* ── Alerts & Notices ───────────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; font-size: 0.9rem; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-warn    { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.oree-info, .cache-info { border-radius: var(--radius); padding: 0.6rem 1rem; font-size: 0.85rem; font-weight: 500; margin-bottom: 1rem; }
.oree-info  { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.cache-info { background: #fefce8; color: #854d0e; border: 1px solid #fde68a; }

.no-data-notice { background: rgba(230,191,25,0.12); border: 1px solid #E6BF19; border-radius: var(--radius); padding: 0.6rem 1rem; margin-bottom: 1rem; font-size: 0.9rem; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.recalc-link { color: var(--orange); font-weight: 600; text-decoration: none; white-space: nowrap; }
.recalc-link:hover { text-decoration: underline; }

/* ── Status ─────────────────────────────────────────────────── */
.status { font-size: 0.8rem; padding: 0.2rem 0.8rem; border-radius: 99px; font-weight: 600; }
.status-success { background: #dcfce7; color: #166534; }
.status-error   { background: #fef2f2; color: #991b1b; }
.status-pending { background: #fef3c7; color: #92400e; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge { display: inline-block; font-size: 0.75rem; padding: 0.2rem 0.6rem; border-radius: 99px; font-weight: 600; }
.badge-pending { background: #fef3c7; color: #92400e; }

/* Inline tag badges (stations page) */
.badge-tag { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 0.1rem 0.4rem; border-radius: 4px; vertical-align: middle; margin-left: 0.4rem; }
.badge-rdn   { background: #dbeafe; color: #1d4ed8; }
.badge-fixed { background: #fce7d6; color: #c2410c; }

/* Date status (calculate page) */
.date-status { font-size: 0.9rem; font-weight: 600; padding: 0.4rem 0.75rem; border-radius: var(--radius); margin-bottom: 0.5rem; }
.date-status.loading   { color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); }
.date-status.found     { color: var(--success); background: #f0fdf4; border: 1px solid #bbf7d0; }
.date-status.not-found { color: #92400e; background: #fffbeb; border: 1px solid #fde68a; }

/* ── Cards ──────────────────────────────────────────────────── */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.card-header { padding: 1rem 1.25rem 0.5rem; display: flex; justify-content: space-between; align-items: center; }
.card-header h3 { font-size: 1.1rem; color: var(--dark); }
.card-body    { padding: 0.5rem 1.25rem; }
.card-actions { padding: 0.75rem 1.25rem; display: flex; gap: 0.5rem; border-top: 1px solid var(--border); }

/* ── Dashboard Stats ────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.stat-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.35rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--dark); line-height: 1.2; }
.stat-sub   { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }
.stat-ok    { color: var(--success); }
.stat-warn  { color: var(--pending); }
.stat-err   { color: var(--error); }

.dash-section { margin-bottom: 1.5rem; }
.dash-section h2 { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.75rem; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; margin-bottom: 1.5rem; }

.table {
    width: 100%;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}
.table th { background: var(--dark); color: white; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.75rem 1rem; text-align: left; }
.table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }

/* Archive & calc tables (light header) */
.archive-table,
.calc-table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.archive-table th,
.calc-table th { background: var(--bg); font-weight: 600; font-size: 0.82rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.archive-table td,
.calc-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.archive-table tr:last-child td,
.calc-table tr:last-child td { border-bottom: none; }

.clickable-row { cursor: pointer; transition: background 0.15s; }
.clickable-row:hover { background: rgba(244,121,15,0.05); }

.price-buy    { color: #3399FF; }
.price-sell   { color: var(--orange); font-weight: 600; }
.price-profit { color: var(--success); font-weight: 600; }

.interval-badge { display: inline-block; width: 28px; height: 28px; line-height: 28px; text-align: center; border-radius: 50%; color: white; font-weight: 700; font-size: 0.85rem; }

/* ── Archive cells ──────────────────────────────────────────── */
.search-form { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; align-items: center; }
.search-date { padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.95rem; font-family: inherit; }

.cell-date { font-weight: 700; color: var(--dark); white-space: nowrap; }
.cell-intervals { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.cell-avg { font-weight: 700; color: var(--orange); font-family: ui-monospace, monospace; white-space: nowrap; }

.iv-chip { display: inline-flex; flex-direction: column; padding: 0.25rem 0.6rem; border-left: 3px solid; border-radius: 4px; background: var(--bg); border-top: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; line-height: 1.3; gap: 0.05rem; }
.iv-time  { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.iv-price { font-size: 0.88rem; font-weight: 700; font-family: ui-monospace, monospace; }

/* ── Interval Summary Cards ─────────────────────────────────── */
.calc-summary-top { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.summary-interval-card { background: var(--card-bg); padding: 0.75rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); }
.summary-interval-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.25rem; }
.summary-interval-time   { font-weight: 700; font-size: 1rem; }
.summary-interval-price  { font-weight: 700; font-size: 1.15rem; }
.summary-interval-detail { font-size: 0.8rem; color: var(--text-muted); }

/* Interval list (archive detail) */
.intervals-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.interval-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; }
.interval-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.interval-time   { font-weight: 600; font-size: 0.95rem; }
.interval-price  { font-weight: 700; font-size: 1.1rem; }
.interval-detail { font-size: 0.8rem; color: var(--text-muted); }

/* ── Tariff List (stations) ─────────────────────────────────── */
.tariff-list { display: flex; flex-direction: column; gap: 0.25rem; }
.tariff-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; border-left: 3px solid; padding: 0.15rem 0.5rem; background: var(--bg); border-radius: 0 5px 5px 0; min-width: 180px; }
.tariff-label { color: var(--text-muted); font-size: 0.82rem; font-family: 'SF Mono', SFMono-Regular, Menlo, monospace; font-weight: 500; }
.tariff-price { font-weight: 700; font-size: 0.88rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; margin-bottom: 1rem; border-bottom: 2px solid var(--border); }
.tab { padding: 0.6rem 1.2rem; background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 0.95rem; font-weight: 600; color: var(--text-muted); cursor: pointer; font-family: inherit; transition: all 0.2s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--orange); border-bottom-color: var(--orange); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Donut Chart ────────────────────────────────────────────── */
.donut-legend  { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem 1rem; margin-bottom: 1rem; }
.legend-item   { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 600; }
.legend-dot    { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.donut-wrapper { display: flex; justify-content: center; margin-bottom: 1.5rem; }
#donutChart    { max-width: 320px; max-height: 320px; width: 100%; }

/* ── OREE ───────────────────────────────────────────────────── */
.oree-day-card   { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem; }
.oree-day-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.oree-day-date   { font-weight: 700; font-size: 1rem; }
.oree-day-avg    { font-size: 0.85rem; color: var(--text-muted); }
.oree-hours-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 0.4rem; }
.oree-hour-cell  { display: flex; flex-direction: column; align-items: center; padding: 0.3rem; background: var(--bg); border-radius: 4px; border: 1px solid var(--border); }
.oree-hour-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }
.oree-hour-price { font-size: 0.85rem; font-weight: 700; color: var(--text); }

/* ── Archive detail nav ─────────────────────────────────────── */
.detail-nav { margin-bottom: 1.5rem; }
.detail-nav h1 { margin: 0.5rem 0 0.25rem; }
.detail-meta { font-size: 0.85rem; color: var(--text-muted); }
.back-link { color: var(--orange); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.back-link:hover { text-decoration: underline; }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.5rem; }
.page-info,
.page-num { font-size: 0.9rem; color: var(--text-muted); }

/* ── Misc ───────────────────────────────────────────────────── */
.price-display { font-size: 1.25rem; font-weight: 700; color: var(--orange); font-variant-numeric: tabular-nums; }
.price-display.muted { color: var(--text-muted); font-weight: 400; font-size: 0.9rem; }

.interval-row   { display: flex; justify-content: space-between; padding: 0.15rem 0; font-variant-numeric: tabular-nums; }
.interval-hours { font-family: 'SF Mono', SFMono-Regular, Menlo, monospace; font-size: 0.85rem; color: var(--text-muted); }

.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.actions    { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.inline     { display: inline; }

.key-display { margin-top: 0.75rem; }
.key-display label { font-size: 0.8rem; font-weight: 600; display: block; margin-bottom: 0.2rem; }
.key-display code { background: white; padding: 0.5rem 0.75rem; border-radius: 4px; font-size: 0.8rem; display: block; word-break: break-all; border: 1px solid var(--border); }

input[type="date"] { font-size: 1.1rem; font-family: inherit; padding: 0.6rem 0.8rem; }

/* ── Login ──────────────────────────────────────────────────── */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--dark); }
.login-card      { background: white; border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-header    { text-align: center; margin-bottom: 1.5rem; }
.login-logo      { font-size: 2.5rem; display: block; margin-bottom: 0.5rem; }
.login-header h1 { color: var(--dark); font-size: 1.3rem; margin-bottom: 0; }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); }
.empty-state a { color: var(--orange); font-weight: 600; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
    .container  { padding: 1rem; }
    .navbar     { padding: 0 1rem; }
    .nav-links  { gap: 0.2rem; }
    .nav-link   { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .table td, .table th { padding: 0.5rem 0.6rem; }
    .table      { font-size: 0.85rem; }
    .form-grid  { grid-template-columns: 1fr; }
    .calc-summary-top { grid-template-columns: 1fr; }
    .intervals-list   { grid-template-columns: 1fr; }
    .oree-hours-grid  { grid-template-columns: repeat(4, 1fr); }
    .tabs { overflow-x: auto; }
}

/* ── Station carousel (dashboard) ───────────────────────────── */
.stations-progress {
    height: 3px;
    background: var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
    margin-top: -1px;
}
.stations-progress-fill {
    height: 100%;
    background: var(--orange);
    width: 0%;
}
.stations-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}
.stations-dots { display: flex; gap: 0.4rem; }
.stations-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.3s;
}
.stations-dot.active { background: var(--orange); }
.stations-counter { font-size: 0.8rem; color: var(--text-muted); }
