/* =========================================================
   Sarthi Dashboard — Main Stylesheet
   ========================================================= */

:root {
    --bg: #f0f4f8;
    --surface: #ffffff;
    --surface2: #f8fafc;
    --border: #e2e8f0;
    --text: #1a202c;
    --text-muted: #718096;
    --blue: #3b82f6;
    --green: #22c55e;
    --emerald: #10b981;
    --red: #ef4444;
    --orange: #f97316;
    --purple: #8b5cf6;
    --yellow: #eab308;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --transition: .2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 20px 16px 40px;
}

/* ── Container ─────────────────────────── */
.container { max-width: 1440px; margin: 0 auto; }

/* ── Header ────────────────────────────── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 28px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo {
    width: 48px; height: 48px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 22px;
}

h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.api-config {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
}

.api-config label { color: var(--text-muted); font-weight: 500; white-space: nowrap; }

.api-config input {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    width: 200px;
    font-family: 'Inter', monospace;
    outline: none;
    transition: border-color var(--transition);
}
.api-config input:focus { border-color: var(--blue); }

#connect-btn {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
    white-space: nowrap;
}
#connect-btn:hover { background: #2563eb; }

/* ── Status Badge ───────────────────────── */
.status-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .3px;
}
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
}
.status-connected { background: #dcfce7; color: #166534; }
.status-connected .status-dot { background: #22c55e; }
.status-error { background: #fee2e2; color: #991b1b; }
.status-error .status-dot { background: #ef4444; }
.status-connecting { background: #fef9c3; color: #713f12; }
.status-connecting .status-dot { background: #eab308; animation: pulse 1.2s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}

/* ── Live Badge ─────────────────────────── */
.live-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    background: #10b981;
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}
.live-dot {
    width: 8px; height: 8px;
    background: white;
    border-radius: 50%;
    animation: pulse 1s infinite;
}

/* ── Error Banner ───────────────────────── */
.error-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
    font-size: 14px;
    color: #991b1b;
}
.error-banner i { font-size: 16px; flex-shrink: 0; }
.error-banner span { flex: 1; }
.error-banner code {
    background: #fee2e2;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}
.error-banner button {
    background: none;
    border: none;
    color: #991b1b;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    transition: background var(--transition);
}
.error-banner button:hover { background: #fecaca; }
.hidden { display: none !important; }

/* ── Cards Grid ─────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.metric-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    transition: transform var(--transition), box-shadow var(--transition);
}
.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,.1);
}

.card-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    color: white;
    flex-shrink: 0;
}
.bg-blue    { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.bg-green   { background: linear-gradient(135deg, #22c55e, #16a34a); }
.bg-emerald { background: linear-gradient(135deg, #10b981, #059669); }
.bg-red     { background: linear-gradient(135deg, #ef4444, #dc2626); }
.bg-orange  { background: linear-gradient(135deg, #f97316, #ea580c); }
.bg-purple  { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }

.card-body { flex: 1; min-width: 0; }
.card-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); margin-bottom: 4px; }
.card-value { font-size: 28px; font-weight: 700; letter-spacing: -.5px; line-height: 1; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.skeleton { display: inline-block; background: #e2e8f0; border-radius: 4px; color: transparent; min-width: 60px; animation: shimmer 1.4s infinite; }
@keyframes shimmer { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ── Charts ─────────────────────────────── */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.chart-card { padding: 20px; }

.chart-large { /* default */ }
.chart-small { /* default */ }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.card-header h2 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}
.card-header h2 i { color: var(--blue); }

.chart-badge {
    background: #eff6ff;
    color: var(--blue);
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.error-badge { background: #fef2f2; color: var(--red); }

.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { max-height: 100%; }

/* ── Tables Row ─────────────────────────── */
.tables-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.full-row { margin-bottom: 20px; }

.table-card, .table-card-full { padding: 20px; }

.table-controls { display: flex; align-items: center; gap: 10px; }
.table-controls label { font-size: 13px; color: var(--text-muted); }
.table-controls select {
    margin-left: 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    outline: none;
    background: white;
    cursor: pointer;
}

.history-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.segmented-control {
    display: inline-flex;
    align-items: center;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface2);
}

.segment-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 7px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.segment-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.table-scroll { overflow-x: auto; max-height: 340px; overflow-y: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table thead {
    position: sticky;
    top: 0;
    background: var(--surface2);
    z-index: 1;
}
.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8faff; }
.data-table tbody tr:last-child td { border-bottom: none; }

.loading-cell {
    text-align: center;
    padding: 32px !important;
    color: var(--text-muted);
    font-size: 14px;
}
.loading-cell i { margin-right: 8px; color: var(--blue); }

/* ── Bar cells ──────────────────────────── */
.bar-cell { min-width: 100px; }
.bar-bg {
    background: #e2e8f0;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--blue), #6366f1);
    transition: width .6s ease;
}
.bar-fill.bar-ip { background: linear-gradient(90deg, var(--emerald), #0891b2); }

/* ── Status colors ──────────────────────── */
.status-2xx { color: var(--emerald); font-weight: 600; }
.status-3xx { color: var(--blue);    font-weight: 600; }
.status-4xx { color: var(--orange);  font-weight: 600; }
.status-5xx { color: var(--red);     font-weight: 600; }

/* ── Trend icons ────────────────────────── */
.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--text-muted); }

/* ── Number formatting ──────────────────── */
.num { font-variant-numeric: tabular-nums; }

/* ── URL cell ───────────────────────────── */
.url-cell {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: monospace;
    font-size: 12px;
    color: #2563eb;
}

.country-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 180px;
    white-space: nowrap;
    flex-wrap: wrap;
}

.country-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 20px;
    padding: 0 6px;
    border-radius: 6px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 10px;
    font-weight: 700;
}

.isp-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 160px;
    max-width: 260px;
}

.isp-main,
.isp-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.isp-main {
    color: var(--text);
    font-weight: 600;
}

.isp-sub {
    color: var(--text-muted);
    font-size: 11px;
}

.country-sub {
    color: var(--text-muted);
    font-size: 11px;
    white-space: nowrap;
}

/* ── Rank badge ─────────────────────────── */
.rank {
    width: 24px; height: 24px;
    border-radius: 6px;
    background: #eff6ff;
    color: var(--blue);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}
.rank-1 { background: #fef9c3; color: #a16207; }
.rank-2 { background: #f1f5f9; color: #64748b; }
.rank-3 { background: #fef3c7; color: #92400e; }

/* ── Footer ─────────────────────────────── */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
    padding: 14px 20px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}
.footer select {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    outline: none;
    background: white;
    margin-left: 6px;
    cursor: pointer;
}

/* ── Responsive ─────────────────────────── */
@media (max-width: 1100px) {
    .charts-row { grid-template-columns: 1fr; }
    .tables-row { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
    .cards-grid { grid-template-columns: 1fr 1fr; }
    .header { flex-direction: column; align-items: flex-start; }
    .api-config input { width: 140px; }
    h1 { font-size: 20px; }
}
@media (max-width: 480px) {
    .cards-grid { grid-template-columns: 1fr; }
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-img {
    height: 50px;  /* Adjust as needed */
    width: auto;
    object-fit: contain;
}
