/* =========================================================================
   Gambit Bot — application design system
   Layout: fixed dark sidebar + light content area.
   Loaded from base.html; page-specific styles stay in their templates.
   ========================================================================= */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #94a3b8;

    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --accent-soft: #eff6ff;
    --green: #16a34a;
    --green-soft: #f0fdf4;
    --red: #dc2626;
    --red-soft: #fef2f2;
    --amber: #d97706;
    --teal: #0d9488;
    --purple: #7c3aed;

    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #f8fafc;
    --sidebar-active-bg: #1e293b;

    --sidebar-w: 240px;
    --topbar-h: 60px;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06);
    --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--text); }

code { background: #eef2f7; border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }

.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-green { color: var(--green); font-weight: 600; }
.text-red { color: var(--red); font-weight: 600; }
.text-muted { color: var(--muted); }

/* ---------------------------------------------------------------- layout */

.app-shell { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.25s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    color: var(--sidebar-text-active);
}

.brand .brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    flex: none;
}

.brand .brand-name {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}

.brand .brand-sub {
    display: block;
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--sidebar-text);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
}

.nav-label {
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #64748b;
    padding: 14px 10px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    margin: 2px 0;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 0.86rem;
    transition: background 0.15s, color 0.15s;
}

.nav-item i {
    width: 18px;
    text-align: center;
    font-size: 0.92rem;
    flex: none;
}

.nav-item:hover { background: rgba(148, 163, 184, 0.08); color: #e2e8f0; }

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    box-shadow: inset 3px 0 0 var(--accent);
}

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

/* main column */

.main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 500;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
}

.topbar .page-title {
    font-size: 1.02rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar .page-title i { color: var(--accent); }

.topbar .spacer { flex: 1; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-2);
    font-size: 0.85rem;
}

.user-chip .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.icon-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-size: 0.85rem;
}

.icon-btn:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }

.menu-toggle { display: none; }

.content {
    flex: 1;
    padding: 24px;
    max-width: 1500px;
    width: 100%;
}

/* ------------------------------------------------------------- messages */

.messages { margin-bottom: 18px; }

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid;
    font-size: 0.87rem;
    margin-bottom: 8px;
    background: var(--surface);
}

.alert i { margin-top: 2px; }
.alert .alert-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
}
.alert .alert-close:hover { opacity: 1; }

.alert-success { border-color: #bbf7d0; background: var(--green-soft); color: #15803d; }
.alert-error, .alert-danger { border-color: #fecaca; background: var(--red-soft); color: #b91c1c; }
.alert-warning { border-color: #fde68a; background: #fffbeb; color: #b45309; }
.alert-info, .alert-debug { border-color: #bfdbfe; background: var(--accent-soft); color: var(--accent-strong); }

/* ------------------------------------------------------------ page head */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.page-head h1 { font-size: 1.25rem; }

.page-head .sub { color: var(--text-2); font-size: 0.85rem; margin-top: 2px; }

.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ----------------------------------------------------------------- KPIs */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    display: flex;
    gap: 14px;
    align-items: center;
}

.kpi .kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex: none;
    background: var(--accent-soft);
    color: var(--accent);
}

.kpi .kpi-icon.green { background: var(--green-soft); color: var(--green); }
.kpi .kpi-icon.red { background: var(--red-soft); color: var(--red); }
.kpi .kpi-icon.amber { background: #fffbeb; color: var(--amber); }
.kpi .kpi-icon.purple { background: #f5f3ff; color: var(--purple); }
.kpi .kpi-icon.teal { background: #f0fdfa; color: var(--teal); }

.kpi .kpi-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
}

.kpi .kpi-value {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.kpi .kpi-sub { font-size: 0.75rem; color: var(--text-2); }

/* ---------------------------------------------------------------- cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 14px;
}

.card-title i { color: var(--accent); }

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

.info-grid .info-item .k {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
}

.info-grid .info-item .v { font-weight: 500; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- tables */

.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    margin-bottom: 20px;
}

table { width: 100%; border-collapse: collapse; }

th, td {
    padding: 11px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

td .cell-sub { display: block; font-size: 0.76rem; color: var(--muted); }

.empty-state {
    text-align: center;
    padding: 46px 20px;
    color: var(--muted);
}

.empty-state i { font-size: 1.6rem; display: block; margin-bottom: 10px; opacity: 0.6; }

/* --------------------------------------------------------------- status */

.status {
    padding: 3px 11px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.74rem;
    display: inline-block;
    border: 1px solid transparent;
    text-transform: capitalize;
}

.status-running { background: var(--accent-soft); color: var(--accent-strong); border-color: #bfdbfe; }
.status-open, .status-successful { background: var(--green-soft); color: #15803d; border-color: #bbf7d0; }
.status-closed, .status-liquidated, .status-failed { background: var(--red-soft); color: #b91c1c; border-color: #fecaca; }
.status-halted, .status-partially_successful { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.status-charity { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.status-profit_target_hit { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.status-revival_close { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }

.pill-long { color: var(--green); font-weight: 600; }
.pill-short { color: var(--red); font-weight: 600; }

.bot-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.8rem;
    border: 1px solid;
}

.bot-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.bot-online { background: var(--green-soft); color: #15803d; border-color: #bbf7d0; }
.bot-online .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18); }
.bot-degraded { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.bot-degraded .dot { background: var(--amber); }
.bot-offline { background: var(--red-soft); color: #b91c1c; border-color: #fecaca; }
.bot-offline .dot { background: var(--red); }

/* -------------------------------------------------------------- buttons */

.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 16px;
    font-weight: 600;
    font-size: 0.84rem;
    font-family: var(--font);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    transition: all 0.15s;
    line-height: 1.4;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 5px 11px; font-size: 0.78rem; border-radius: 7px; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------------------------------------------------------------- forms */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-grid .full { grid-column: 1 / -1; }

.field label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-2);
}

.field .hint { font-size: 0.72rem; color: var(--muted); margin-top: 3px; }

.input, .field input, .field select {
    width: 100%;
    padding: 8px 11px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.86rem;
}

.field input:focus, .field select:focus, .input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.field input[readonly] {
    background: #f1f5f9;
    color: var(--muted);
    cursor: not-allowed;
}

/* --------------------------------------------------------------- modals */

.modal-g {
    display: none;
    position: fixed;
    z-index: 2000;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    overflow-y: auto;
    padding: 4vh 16px;
}

.modal-g.open { display: block; }

.modal-card {
    background: var(--surface);
    color: var(--text);
    margin: 0 auto;
    border-radius: 14px;
    width: 100%;
    max-width: 640px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
    overflow: hidden;
}

.modal-card.narrow { max-width: 420px; }
.modal-card.wide { max-width: 900px; }

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
}

.modal-head h2 { font-size: 1rem; }

.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 22px; }

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

/* ----------------------------------------------------- pager and filters */

.pager {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin: 4px 0 20px;
}

.pager a, .pager span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 0.82rem;
    font-weight: 500;
}

.pager a:hover { border-color: var(--accent); color: var(--accent); }
.pager span.current { background: var(--accent); border-color: var(--accent); color: #fff; }

.filter-tabs {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
}

.filter-tabs a {
    padding: 5px 14px;
    border-radius: 7px;
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 600;
}

.filter-tabs a.active { background: var(--accent); color: #fff; }
.filter-tabs a:not(.active):hover { background: var(--bg); }

/* ------------------------------------------------------------ responsive */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 900;
}

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .content { padding: 16px; }
    .mobile-hide { display: none !important; }
    th, td { padding: 9px 10px; font-size: 0.82rem; }
    .form-grid { grid-template-columns: 1fr; }
}
