/* =========================================================
   Timely · admin UI
   ========================================================= */

:root {
    --bg:           #f6f7fb;
    --surface:      #ffffff;
    --surface-2:    #fafbfc;
    --border:       #e6e8ee;
    --border-2:     #eef0f4;

    --text:         #0f172a;
    --text-2:       #475569;
    --text-3:       #94a3b8;

    --brand:        #4f46e5;
    --brand-2:      #6366f1;
    --brand-soft:   #eef2ff;
    --brand-text:   #4338ca;

    --ok:           #16a34a;
    --ok-soft:      #dcfce7;
    --ok-text:      #166534;
    --warn:         #d97706;
    --warn-soft:    #fef3c7;
    --warn-text:    #92400e;
    --bad:          #dc2626;
    --bad-soft:     #fee2e2;
    --bad-text:     #991b1b;

    --radius-sm:    6px;
    --radius:       10px;
    --radius-lg:    14px;

    --shadow-sm:    0 1px 2px rgba(15, 23, 42, .04);
    --shadow:       0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .06);
    --shadow-lg:    0 10px 30px rgba(15, 23, 42, .08);

    --sidebar-w:    248px;
    --topbar-h:     60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); }

/* ---------------------------------------------------------
   App shell: sidebar + content
   --------------------------------------------------------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
}
.sidebar .brand .mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 4px 10px rgba(79, 70, 229, .25);
}

.sidebar nav {
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-weight: 500;
    font-size: 14px;
    transition: background .12s, color .12s;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active {
    background: var(--brand-soft);
    color: var(--brand-text);
}
.sidebar nav a.active svg { color: var(--brand); }
.sidebar nav a svg {
    width: 18px; height: 18px;
    stroke-width: 2;
    color: var(--text-3);
    flex-shrink: 0;
}

.sidebar .userbox {
    border-top: 1px solid var(--border);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar .userbox .avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}
.sidebar .userbox .meta { flex: 1; min-width: 0; line-height: 1.25; }
.sidebar .userbox .meta .name {
    font-weight: 600; font-size: 13px; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar .userbox .meta .role {
    font-size: 11px; color: var(--text-3);
}
.sidebar .userbox .logout-btn {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 8px;
    color: var(--text-3);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
    flex-shrink: 0;
}
.sidebar .userbox .logout-btn:hover {
    background: var(--bad-soft);
    color: var(--bad);
    border-color: #fecaca;
}
.sidebar .userbox .logout-btn svg { width: 16px; height: 16px; }

.content {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky; top: 0; z-index: 5;
}
.topbar .crumbs {
    color: var(--text-3);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.topbar .crumbs .sep { color: var(--text-3); opacity: .6; }
.topbar .crumbs .current { color: var(--text); font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar .today {
    font-size: 13px;
    color: var(--text-2);
    background: var(--surface-2);
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
}

.container {
    padding: 28px;
    max-width: 1400px;
    width: 100%;
}

/* ---------------------------------------------------------
   Page headers
   --------------------------------------------------------- */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.page-head h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.015em;
}
.page-head .sub {
    margin-top: 4px;
    color: var(--text-3);
    font-size: 13px;
}

h1, h2, h3 { color: var(--text); }
h2 { margin: 24px 0 12px; font-size: 15px; font-weight: 600; }

/* ---------------------------------------------------------
   Cards & layout
   --------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
    overflow: hidden;
}
.card .card-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card .card-head h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.card .card-head .hint {
    color: var(--text-3);
    font-size: 12px;
}
.card .card-body { padding: 20px; }
.card.flush .card-body { padding: 0; }

.grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

/* KPI tiles */
.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    overflow: hidden;
}
.kpi .label {
    font-size: 12px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
}
.kpi .value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.1;
    margin-top: 2px;
}
.kpi .delta { font-size: 12px; color: var(--text-3); }
.kpi .icon {
    position: absolute; top: 14px; right: 14px;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--brand-soft);
    color: var(--brand);
    display: grid; place-items: center;
}
.kpi .icon svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------
   Tables
   --------------------------------------------------------- */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}
th, td {
    padding: 12px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border-2);
    font-size: 14px;
    vertical-align: middle;
}
th {
    background: var(--surface-2);
    color: var(--text-3);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
}
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

td .who {
    display: flex; align-items: center; gap: 10px;
}
td .who .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}
td .who .name { font-weight: 600; color: var(--text); }
td .who .email { font-size: 12px; color: var(--text-3); }

.empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-3);
}
.empty svg { width: 36px; height: 36px; color: var(--text-3); margin-bottom: 10px; }

/* ---------------------------------------------------------
   Forms & buttons
   --------------------------------------------------------- */
label {
    display: block;
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 5px;
    font-weight: 500;
}
input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

form.inline {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}
form.inline > div { min-width: 160px; flex: 1; }

/* Segmented control */
.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
}
.segmented a {
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-2);
    background: transparent;
    border-left: 1px solid var(--border);
}
.segmented a:first-child { border-left: 0; }
.segmented a:hover { background: var(--surface-2); color: var(--text); }
.segmented a.active {
    background: var(--brand-soft);
    color: var(--brand-text);
}

tfoot td {
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    font-weight: 600;
}

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: background .12s, transform .04s, box-shadow .12s;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}
button:hover, .btn:hover { background: var(--brand-2); color: #fff; }
button:active, .btn:active { transform: translateY(1px); }
.btn.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--surface-2); color: var(--text); }
.btn.danger    { background: var(--bad); }
.btn.danger:hover { background: #b91c1c; color: #fff; }
.btn.ghost     { background: transparent; color: var(--brand); box-shadow: none; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { padding: 6px 12px; font-size: 13px; }

.btn svg { width: 14px; height: 14px; }

/* ---------------------------------------------------------
   Alerts
   --------------------------------------------------------- */
.msg {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 14px;
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.msg svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.msg.ok  { background: var(--ok-soft); color: var(--ok-text); border-color: #bbf7d0; }
.msg.err { background: var(--bad-soft); color: var(--bad-text); border-color: #fecaca; }

/* ---------------------------------------------------------
   Pills / status
   --------------------------------------------------------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #f1f5f9;
    color: var(--text-2);
}
.pill.ok  { background: var(--ok-soft); color: var(--ok-text); }
.pill.low { background: var(--bad-soft); color: var(--bad-text); }
.pill.mid { background: var(--warn-soft); color: var(--warn-text); }
.pill.dot::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.pill.ok.dot::before  { background: var(--ok); }
.pill.low.dot::before { background: var(--bad); }
.pill.mid.dot::before { background: var(--warn); }

.pill.live { background: var(--ok-soft); color: var(--ok-text); }
.pill.live::before {
    content: '';
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 0 rgba(22, 163, 74, .6);
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, .55); }
    70%  { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

/* ---------------------------------------------------------
   Login page
   --------------------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(800px 400px at 80% -10%, rgba(99, 102, 241, .14), transparent 60%),
        radial-gradient(600px 400px at 0% 100%, rgba(244, 114, 182, .10), transparent 60%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 32px;
}
.login-card .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 22px;
}
.login-card .brand .mark {
    width: 36px; height: 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 6px 14px rgba(79, 70, 229, .3);
}
.login-card .brand .name { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.login-card h1 {
    margin: 4px 0 4px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.015em;
}
.login-card .sub { color: var(--text-3); font-size: 14px; margin: 0 0 22px; }
.login-card label { margin-top: 14px; }
.login-card label:first-of-type { margin-top: 0; }
.login-card button { width: 100%; margin-top: 20px; padding: 11px; }
.login-foot {
    margin-top: 18px;
    text-align: center;
    color: var(--text-3);
    font-size: 12px;
}

/* ---------------------------------------------------------
   Activity timeline (heatmap)
   --------------------------------------------------------- */
.timeline { display: flex; flex-direction: column; gap: 6px; }
.hour-row { display: flex; align-items: center; gap: 10px; }
.hour-label {
    width: 50px;
    font-size: 11px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.minutes { display: flex; flex: 1; gap: 2px; }
.minute {
    flex: 1;
    height: 22px;
    border-radius: 3px;
    background: #eef2f7;
    transition: transform .06s;
}
.minute:hover { transform: scale(1.4); z-index: 1; }
/* Tracked but idle minute (in-session, 0 events) */
.minute.lvl0 { background: #ef4444; }   /* red    — idle */
.minute.lvl1 { background: #fb923c; }   /* orange — 1-9 events */
.minute.lvl2 { background: #facc15; }   /* yellow — 10-29 events */
.minute.lvl3 { background: #86efac; }   /* light green — 30-99 events */
.minute.lvl4 { background: #16a34a; }   /* dark  green — 100+ events */

.timeline-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    font-size: 12px;
    color: var(--text-3);
}
.timeline-legend .swatch {
    width: 14px; height: 14px; border-radius: 3px;
    background: #eef2f7;
}
.timeline-legend .swatch.lvl0 { background: #ef4444; }
.timeline-legend .swatch.lvl1 { background: #fb923c; }
.timeline-legend .swatch.lvl2 { background: #facc15; }
.timeline-legend .swatch.lvl3 { background: #86efac; }
.timeline-legend .swatch.lvl4 { background: #16a34a; }

/* Custom hover tooltip for the activity timeline */
.tl-tooltip {
    position: fixed;
    z-index: 1000;
    display: none;
    min-width: 180px;
    padding: 10px 12px;
    background: #0f172a;
    color: #f8fafc;
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .35);
    font-size: 12px;
    line-height: 1.4;
    pointer-events: none;
}
.tl-tooltip-time {
    font-weight: 600;
    font-size: 13px;
    color: #fff;
    margin-bottom: 8px;
    font-variant-numeric: tabular-nums;
}
.tl-tooltip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}
.tl-tooltip-row .tl-icon {
    width: 16px; height: 16px;
    display: grid; place-items: center;
    color: #94a3b8;
    flex-shrink: 0;
}
.tl-tooltip-row .tl-icon svg { width: 14px; height: 14px; }
.tl-tooltip-row .tl-label { color: #cbd5e1; flex: 1; }
.tl-tooltip-row .tl-val,
.tl-tooltip-total .tl-val {
    font-weight: 600;
    color: #fff;
    font-variant-numeric: tabular-nums;
}
.tl-tooltip-total {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, .12);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #cbd5e1;
}

/* ---------------------------------------------------------
   Screenshots
   --------------------------------------------------------- */
.shots {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.shot {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
    transition: border-color .12s, transform .12s, box-shadow .12s;
    display: block;
}
.shot:hover {
    border-color: var(--brand);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.shot img {
    width: 100%;
    display: block;
    aspect-ratio: 16/10;
    object-fit: cover;
    background: #f1f5f9;
}
.shot .cap {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------
   Details / dropdown actions
   --------------------------------------------------------- */
details.actions { position: relative; }
details.actions > summary {
    list-style: none;
    cursor: pointer;
    color: var(--text-2);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
details.actions > summary::-webkit-details-marker { display: none; }
details.actions > summary:hover { background: var(--surface-2); }
details.actions[open] > summary { background: var(--surface-2); }
details.actions .menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 12px;
    min-width: 240px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ---------------------------------------------------------
   Responsive
   --------------------------------------------------------- */
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; top: 0; left: 0; right: 0;
        height: auto;
        flex-direction: row;
        align-items: center;
        z-index: 10;
    }
    .sidebar nav { flex-direction: row; padding: 8px; }
    .sidebar .brand { border-bottom: 0; border-right: 1px solid var(--border); flex: 0 0 auto; }
    .sidebar .userbox { border-top: 0; border-left: 1px solid var(--border); padding: 0 14px; }
    .sidebar .userbox .meta .logout { display: inline-block; }
    .content { padding-top: var(--topbar-h); }
    .container { padding: 18px; }
}
