/* Lemon MGA — brand palette: warm lime over near-black.
 * Lemon logo colors sampled from the APK banner.
 */

:root {
    /* backgrounds */
    --bg-root:    #0a0d0a;
    --bg-panel:   #121612;
    --bg-panel-2: #181d18;
    --bg-raise:   #1e241e;
    --bg-chip:    #242a24;

    /* borders */
    --border:        #232a23;
    --border-strong: #2f3830;

    /* text */
    --text:       #e0e5dd;
    --text-dim:   #99a09a;
    --text-faint: #666d66;

    /* brand colors — sampled directly from APK res/values/colors.xml.
     * Primary = teal from the lemon banner (lemon_green_color = #06927b).
     * Lemon yellow is reserved for sparing accents only (status dots, small
     * flourishes) because solid yellow at scale reads harsh in dark UI.
     *
     * NOTE: --lime is now TEAL. The variable name is retained so the ~25
     * existing CSS call sites don't need per-site edits; semantically it
     * means "brand primary". Use --lemon for the sparing yellow pop.
     */
    --lime:        #06927b;    /* PRIMARY — teal, lemon_green_color */
    --lime-soft:   #048370;    /* hover / pressed (slightly darker) */
    --lime-deep:   #055d4e;    /* text accent on light bg */
    --lime-glow:   rgba(6, 146, 123, 0.22);
    --teal-brand:  #06927b;    /* alias for --lime, kept for clarity */
    --teal-deep:   #053334;    /* deep teal highlight */
    --teal-light:  #40f3d5;    /* bright cyan — focused state */
    --lemon:       #e3dd3a;    /* sparing yellow accent — status dots, hints */
    --lemon-glow:  rgba(227, 221, 58, 0.22);

    /* status */
    --red:    #e85656;
    --amber:  #e9b23e;
    /* --blue retained as an alias of --lime (teal) so existing refs don't
     * break and no new blue leaks into the UI. */
    --blue:   #06927b;

    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;
}

* { box-sizing: border-box; }

html, body {
    background: var(--bg-root);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--lime);
    text-decoration: none;
    transition: color .12s ease;
}
a:hover { color: var(--lime-soft); }

.font-mono { font-family: var(--font-mono) !important; letter-spacing: 0 !important; }

/* ===== App shell ===== */

.app-body { background: var(--bg-root); min-height: 100vh; }

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

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

.brand {
    padding: 1rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border-bottom: 1px solid var(--border);
}

.brand img {
    width: 32px; height: 32px;
    border-radius: 7px;
    display: block;
}

.brand-wordmark {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    letter-spacing: 0.01em;
    line-height: 1.1;
}

.brand-sub {
    font-size: 0.68rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-top: 2px;
}

.sidebar .nav {
    padding: 0.75rem 0.5rem;
    gap: 1px;
    flex: 1;
    overflow-y: auto;
}

.sidebar .nav-link {
    color: var(--text-dim);
    padding: 0.55rem 0.85rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background .1s, color .1s;
    position: relative;
}

.sidebar .nav-link i { font-size: 1rem; width: 18px; text-align: center; opacity: 0.9; }

.sidebar .nav-link:hover { background: var(--bg-raise); color: var(--text); }

.sidebar .nav-link.active {
    background: var(--bg-raise);
    color: var(--text);
}
.sidebar .nav-link.active::before {
    content: '';
    position: absolute;
    left: -0.5rem;
    top: 25%;
    bottom: 25%;
    width: 2px;
    background: var(--lime);
    border-radius: 2px;
}
.sidebar .nav-link.active i { color: var(--lime); opacity: 1; }

.sidebar-foot {
    padding: 0.85rem 1.1rem;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--text-dim);
}
.sidebar-foot .user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.sidebar-foot .user-name {
    color: var(--text);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.sidebar-foot .user-name i { color: var(--lime); }
.sidebar-foot a {
    color: var(--text-faint);
    padding: 0.3rem 0.4rem;
    border-radius: var(--radius-sm);
}
.sidebar-foot a:hover { color: var(--red); background: var(--bg-raise); }

/* ===== Main ===== */

.app-main { flex: 1; min-width: 0; }

.topbar {
    padding: 0.9rem 1.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-root);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar .page-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}
.topbar .page-sub {
    color: var(--text-faint);
    font-size: 0.78rem;
    margin-top: 2px;
    display: block;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-faint);
    font-size: 0.78rem;
}

.page-body { padding: 1.5rem 1.75rem 3rem; }

.flash-stack { padding: 0.75rem 1.75rem 0; }

/* ===== Cards ===== */

.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
    overflow: hidden;
}

.card + .card { margin-top: 1rem; }

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 1.1rem;
    font-weight: 600;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.card-header i { color: var(--text-faint); margin-right: 0.3rem; }
.card-header .card-count {
    color: var(--text-faint);
    font-weight: 500;
    font-size: 0.82rem;
    margin-left: 0.4rem;
}

.card-body { padding: 1.1rem; }
.card-body.p-0 { padding: 0; }

/* ===== Stat tiles ===== */

.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    position: relative;
    transition: border-color .12s ease, transform .12s ease;
    display: block;
    color: var(--text);
}
.stat-card:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.stat-card .stat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.stat-card .stat-label {
    color: var(--text-dim);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

.stat-card .stat-icon {
    color: var(--text-faint);
    font-size: 1rem;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    line-height: 1.1;
}

.stat-card .stat-sub {
    color: var(--text-faint);
    font-size: 0.78rem;
    margin-top: 0.3rem;
}

/* ===== Forms ===== */

.form-control, .form-select {
    background: var(--bg-root);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.45rem 0.7rem;
    font-size: 0.9rem;
    transition: border-color .12s, box-shadow .12s;
}
.form-control:focus, .form-select:focus {
    background: var(--bg-root);
    color: var(--text);
    border-color: var(--lime);
    box-shadow: 0 0 0 3px var(--lime-glow);
    outline: none;
}
.form-control.is-invalid, .form-select.is-invalid {
    border-color: var(--red);
    background-image: none;
    padding-right: 0.7rem;
}
.form-control.is-invalid:focus, .form-select.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(232, 86, 86, 0.18);
}
.form-control::placeholder { color: var(--text-faint); }

.form-label {
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.82rem;
    margin-bottom: 0.3rem;
    letter-spacing: 0.01em;
}

.form-text, .form-text.text-muted { color: var(--text-faint) !important; font-size: 0.78rem; }
.invalid-feedback { color: var(--red); font-size: 0.78rem; }

.form-check-input {
    background-color: var(--bg-root);
    border-color: var(--border-strong);
}
.form-check-input:checked {
    background-color: var(--lime);
    border-color: var(--lime);
}
.form-check-input:focus { box-shadow: 0 0 0 3px var(--lime-glow); border-color: var(--lime); }
.form-check-label { color: var(--text); }

/* ===== Buttons ===== */

.btn {
    border-radius: var(--radius);
    font-weight: 500;
    padding: 0.45rem 0.9rem;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: background .12s, border-color .12s, color .12s, transform .05s;
    border: 1px solid transparent;
}
.btn:active { transform: translateY(1px); }
.btn i { font-size: 0.95em; }

.btn-primary {
    background: var(--lime);
    border-color: var(--lime);
    color: #0a0d0a;
    font-weight: 600;
}
.btn-primary:hover, .btn-primary:focus-visible {
    background: var(--lime-soft);
    border-color: var(--lime-soft);
    color: #0a0d0a;
}

.btn-secondary {
    background: var(--bg-raise);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-secondary:hover {
    background: var(--bg-chip);
    border-color: var(--text-faint);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
}
.btn-ghost:hover {
    background: var(--bg-raise);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-danger {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-dim);
}
.btn-danger:hover {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}

.btn-link {
    color: var(--lime);
    padding: 0;
    font-weight: 500;
}
.btn-link:hover { color: var(--lime-soft); }

.btn-sm {
    font-size: 0.78rem;
    padding: 0.3rem 0.6rem;
}

/* Icon-only button */
.btn-icon {
    padding: 0.35rem 0.5rem;
    font-size: 0.9rem;
}
.btn-icon i { margin: 0; }

/* ===== Tables ===== */

.table {
    color: var(--text);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: var(--bg-panel-2);
    --bs-table-hover-color: var(--text);
    margin: 0;
    font-size: 0.88rem;
}

.table thead th {
    background: transparent;
    color: var(--text-faint);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 0.85rem;
    white-space: nowrap;
}

.table tbody td {
    padding: 0.6rem 0.85rem;
    vertical-align: middle;
    border-color: var(--border);
}

.table tbody tr:last-child td { border-bottom: 0; }

.table a { color: var(--text); border-bottom: 1px dashed var(--border-strong); }
.table a:hover { color: var(--lime); border-bottom-color: var(--lime); }

/* DataTables bootstrap5 overrides */
.dataTables_wrapper { color: var(--text-dim); font-size: 0.84rem; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    background: var(--bg-root);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.3rem 0.6rem;
    font-size: 0.84rem;
}
.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
    outline: none;
    border-color: var(--lime);
    box-shadow: 0 0 0 2px var(--lime-glow);
}
.dataTables_wrapper .dataTables_info { color: var(--text-faint); padding-top: 0.5rem; }

.page-link {
    background: transparent;
    border-color: var(--border);
    color: var(--text-dim);
    font-size: 0.84rem;
    padding: 0.35rem 0.6rem;
}
.page-link:hover { background: var(--bg-raise); color: var(--text); border-color: var(--border-strong); }
.page-item.active .page-link {
    background: var(--lime);
    border-color: var(--lime);
    color: #0a0d0a;
    font-weight: 600;
}
.page-item.disabled .page-link {
    background: transparent;
    color: var(--text-faint);
    border-color: var(--border);
}

/* ===== Modals ===== */

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    color: var(--text);
}
.modal-header { border-color: var(--border); padding: 0.9rem 1.1rem; }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 1.1rem; }
.modal-footer { border-color: var(--border); padding: 0.75rem 1.1rem; }
.btn-close {
    filter: invert(1) grayscale(1);
    opacity: 0.6;
    background-size: 0.7em;
}
.btn-close:hover { opacity: 1; }

/* ===== Badges / tags ===== */

.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1.5;
    border: 1px solid transparent;
}
.badge-pill .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

.badge-success {
    background: rgba(6, 146, 123, 0.1);
    color: var(--lime);
    border-color: rgba(6, 146, 123, 0.25);
}

.badge-danger {
    background: rgba(232, 86, 86, 0.1);
    color: var(--red);
    border-color: rgba(232, 86, 86, 0.25);
}

.badge-muted {
    background: var(--bg-raise);
    color: var(--text-dim);
    border-color: var(--border);
}

.badge-amber {
    background: rgba(233, 178, 62, 0.1);
    color: var(--amber);
    border-color: rgba(233, 178, 62, 0.25);
}

/* Uses lemon yellow — the ONE place yellow is used, deliberately, to
 * distinguish "self_serve" devices from "auto_login" (green) at a glance. */
.badge-info {
    background: rgba(227, 221, 58, 0.08);
    color: var(--lemon);
    border-color: rgba(227, 221, 58, 0.3);
}

/* ===== Code blocks ===== */

pre.code-block {
    background: var(--bg-root);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.8rem 0.9rem;
    color: var(--lime);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    overflow-x: auto;
    margin: 0;
    line-height: 1.5;
}

/* ===== Auth (login/install) page ===== */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-root);
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

/* Hero: the APK banner floats behind the auth card at ~30% opacity, with a
 * blurred vignette on top so the card itself stays legible. */
.auth-shell::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url('brand/banner.png') no-repeat center 20%;
    background-size: min(900px, 90vw) auto;
    opacity: 0.22;
    filter: blur(1px);
    pointer-events: none;
    z-index: 0;
}

.auth-shell::after {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 30% 20%, rgba(6, 146, 123, 0.18) 0%, transparent 45%),
        radial-gradient(circle at 70% 80%, rgba(227, 221, 58, 0.08) 0%, transparent 45%),
        linear-gradient(180deg, rgba(10,13,10,0.55) 0%, rgba(10,13,10,0.85) 100%);
    pointer-events: none;
    z-index: 0;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: rgba(18, 22, 18, 0.82);
    backdrop-filter: blur(12px) saturate(1.1);
    -webkit-backdrop-filter: blur(12px) saturate(1.1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 2rem;
    position: relative;
    z-index: 1;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(6, 146, 123, 0.15),
        0 0 40px rgba(6, 146, 123, 0.08);
}

.brand-logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--lime);
}

.auth-logo {
    display: block;
    margin: 0 auto 1rem;
    width: 64px; height: 64px;
    border-radius: 14px;
}

.auth-card h2 {
    text-align: center;
    margin: 0.25rem 0 1.75rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}

/* ===== Alerts ===== */

.alert {
    border-radius: var(--radius);
    border: 1px solid transparent;
    padding: 0.65rem 0.85rem;
    font-size: 0.88rem;
    display: flex;
    gap: 0.5rem;
    align-items: start;
}
.alert i { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }
.alert-success { background: rgba(6,146,123,0.08); color: var(--lime); border-color: rgba(6,146,123,0.25); }
.alert-danger  { background: rgba(232,86,86,0.08); color: var(--red);  border-color: rgba(232,86,86,0.25); }
.alert-warning { background: rgba(233,178,62,0.08); color: var(--amber); border-color: rgba(233,178,62,0.25); }
.alert-info    { background: rgba(6,146,123,0.08); color: var(--lime); border-color: rgba(6,146,123,0.25); }

/* ===== Misc ===== */

hr { border-color: var(--border); opacity: 1; }

.text-muted { color: var(--text-dim) !important; }
.text-faint { color: var(--text-faint); }

::selection { background: var(--lime); color: #0a0d0a; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-root); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* Tabs (used in Settings) */
.nav-tabs {
    border-bottom: 1px solid var(--border);
    gap: 0.25rem;
}
.nav-tabs .nav-link {
    color: var(--text-dim);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 0.9rem;
    border-radius: 0;
    font-size: 0.88rem;
    font-weight: 500;
}
.nav-tabs .nav-link:hover { color: var(--text); border-color: transparent; }
.nav-tabs .nav-link.active {
    color: var(--lime);
    background: transparent;
    border-color: transparent;
    border-bottom-color: var(--lime);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-faint);
}
.empty-state i.bi {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.75rem;
    opacity: 0.3;
}
.empty-state h4 {
    color: var(--text-dim);
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
}
.empty-state p {
    font-size: 0.88rem;
    max-width: 320px;
    margin: 0 auto 1.25rem;
}

/* Toolbar row (above tables) */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.toolbar .toolbar-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.toolbar .toolbar-filters .form-control,
.toolbar .toolbar-filters .form-select { max-width: 220px; }

/* Install page special */
.install-steps { max-width: 480px; margin: 0 auto; padding: 2rem; }

/* table action cell */
td.actions {
    text-align: right;
    white-space: nowrap;
    width: 1%;
}
td.actions .btn { margin-left: 0.25rem; }

/* Mode chip (username_mode etc.) */
.mode-chip {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    background: var(--bg-chip);
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
}

/* Dot-badge for active/inactive */
.status-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 0.4rem;
}
.status-dot.ok   { background: var(--lime); box-shadow: 0 0 6px rgba(6,146,123,0.55); }
.status-dot.off  { background: var(--text-faint); }
.status-dot.warn { background: var(--amber); }
.status-dot.bad  { background: var(--red); }

/* Tooltip-like hint */
.hint-row {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 0.6rem;
    background: var(--bg-raise);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    color: var(--text-dim);
}
.hint-row i { color: var(--lime); margin-top: 2px; }

/* dropdown button triangle */
.dropdown-toggle::after { opacity: 0.5; }

/* small kbd */
kbd {
    background: var(--bg-root);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 3px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text);
}
