/* ═══════════════════════════════════════════════════════════════
   Lil Bot Panel — Premium Dark Cinematic Design System
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');

:root {
    --void: #07070b;
    --obsidian: #0c0e13;
    --carbon: #14171e;
    --graphite: #1c2028;
    --ash: #262b35;
    --smoke: #54596a;
    --mist: #8a8fa0;
    --bone: #edeae3;
    --amber: #e8b547;
    --amber-soft: rgba(232, 181, 71, 0.12);
    --amber-glow: rgba(232, 181, 71, 0.25);
    --danger: #e55353;
    --danger-soft: rgba(229, 83, 83, 0.12);
    --success: #5bc18c;
    --success-soft: rgba(91, 193, 140, 0.12);
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: "Vazirmatn", system-ui, -apple-system, sans-serif;
    background: var(--void);
    color: var(--bone);
    direction: rtl;
    min-height: 100vh;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse 800px 600px at 80% 0%, rgba(232, 181, 71, 0.06), transparent 60%),
        radial-gradient(ellipse 600px 400px at 20% 100%, rgba(232, 181, 71, 0.03), transparent 60%);
    pointer-events: none;
    z-index: -1;
}

a {
    color: var(--amber);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: #f5c962;
}

/* ─── Topbar ─── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    background: rgba(12, 14, 19, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--ash);
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 18px;
    letter-spacing: -0.02em;
}

.topbar .brand .logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--amber), #c4963a);
    display: grid;
    place-items: center;
    font-size: 18px;
    box-shadow: 0 4px 16px rgba(232, 181, 71, 0.3);
}

.topbar nav {
    display: flex;
    gap: 6px;
    align-items: center;
}

.topbar nav a {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--mist);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.topbar nav a:hover {
    background: var(--graphite);
    color: var(--bone);
    text-decoration: none;
}

.topbar nav a.active {
    background: var(--amber-soft);
    color: var(--amber);
}

/* ─── Mobile Nav ─── */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--bone);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

@media (max-width: 768px) {
    .topbar {
        padding: 12px 16px;
    }
    .topbar nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--obsidian);
        border-bottom: 1px solid var(--ash);
        padding: 12px;
        gap: 4px;
    }
    .topbar nav.open {
        display: flex;
    }
    .topbar nav a {
        width: 100%;
        padding: 12px 16px;
    }
    .mobile-toggle {
        display: block;
    }
}

/* ─── Container ─── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 28px;
}

@media (max-width: 768px) {
    .container {
        padding: 20px 16px;
    }
}

/* ─── Cards Grid ─── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin-bottom: 36px;
}

.card {
    background: var(--carbon);
    border: 1px solid var(--ash);
    border-radius: var(--radius);
    padding: 22px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.card:hover {
    border-color: var(--amber-glow);
    transform: translateY(-2px);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--amber), transparent);
    opacity: 0;
    transition: var(--transition);
}

.card:hover::before {
    opacity: 1;
}

.card .icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 22px;
    margin-bottom: 14px;
    background: var(--amber-soft);
    color: var(--amber);
}

.card .num {
    font-size: 32px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.02em;
}

.card .label {
    color: var(--mist);
    font-size: 13px;
    margin-top: 6px;
}

/* ─── Section ─── */
.section {
    margin-bottom: 36px;
}

.section h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--mist);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section h2::before {
    content: '';
    width: 3px;
    height: 16px;
    background: var(--amber);
    border-radius: 2px;
}

/* ─── Tables ─── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--ash);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--carbon);
    border-radius: var(--radius);
    overflow: hidden;
    min-width: 500px;
}

th, td {
    padding: 12px 16px;
    text-align: right;
    border-bottom: 1px solid var(--graphite);
    font-size: 14px;
    white-space: nowrap;
}

th {
    background: var(--graphite);
    color: var(--mist);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(232, 181, 71, 0.03);
}

/* ─── Badges ─── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.on, .badge.done {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid rgba(91, 193, 140, 0.2);
}

.badge.off, .badge.failed {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(229, 83, 83, 0.2);
}

.badge.pending, .badge.processing {
    background: rgba(232, 181, 71, 0.12);
    color: var(--amber);
    border: 1px solid rgba(232, 181, 71, 0.2);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--ash);
    background: var(--graphite);
    color: var(--bone);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    transition: var(--transition);
    text-decoration: none;
}

.btn:hover {
    border-color: var(--amber-glow);
    color: var(--amber);
}

.btn.primary {
    background: linear-gradient(135deg, var(--amber), #c4963a);
    color: #1a1408;
    border: none;
    font-weight: 700;
}

.btn.primary:hover {
    filter: brightness(1.1);
    color: #1a1408;
}

.btn.danger {
    border-color: rgba(229, 83, 83, 0.3);
    color: var(--danger);
}

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

.btn.sm {
    padding: 6px 10px;
    font-size: 12px;
}

/* ─── Forms ─── */
input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    background: var(--graphite);
    border: 1px solid var(--ash);
    color: var(--bone);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 3px var(--amber-soft);
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--amber);
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-row > * {
    flex: 1;
    min-width: 150px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--mist);
    margin-bottom: 6px;
    font-weight: 500;
}

/* ─── Toggle Switch ─── */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--ash);
    border-radius: 999px;
    transition: var(--transition);
}

.toggle .slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    right: 3px;
    top: 3px;
    background: var(--mist);
    border-radius: 50%;
    transition: var(--transition);
}

.toggle input:checked + .slider {
    background: var(--amber);
}

.toggle input:checked + .slider::before {
    transform: translateX(-20px);
    background: #1a1408;
}

/* ─── Flash Messages ─── */
.flash {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

.flash.ok, .flash.success {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid rgba(91, 193, 140, 0.2);
}

.flash.error {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(229, 83, 83, 0.2);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Gate / Login Screen ─── */
.gate {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    text-align: center;
}

.gate .box {
    max-width: 460px;
    background: var(--carbon);
    border: 1px solid var(--ash);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: var(--shadow);
}

.gate .box .logo {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    margin: 0 auto 20px;
    display: grid;
    place-items: center;
    font-size: 36px;
    background: linear-gradient(135deg, var(--amber), #c4963a);
    box-shadow: 0 8px 32px rgba(232, 181, 71, 0.3);
}

.gate .box h1 {
    font-size: 22px;
    margin-bottom: 12px;
    font-weight: 700;
}

.gate .box p {
    color: var(--mist);
    line-height: 2;
    font-size: 14px;
}

.gate .box .code {
    display: inline-block;
    padding: 3px 10px;
    background: var(--graphite);
    border-radius: 6px;
    font-family: monospace;
    color: var(--amber);
    font-size: 13px;
    border: 1px solid var(--ash);
    direction: ltr;
}

/* ─── Group Detail Header ─── */
.group-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
    padding: 24px;
    background: var(--carbon);
    border-radius: var(--radius);
    border: 1px solid var(--ash);
}

.group-header .avatar {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--graphite), var(--ash));
    display: grid;
    place-items: center;
    font-size: 24px;
    flex-shrink: 0;
}

.group-header h1 {
    font-size: 20px;
    font-weight: 700;
}

.group-header .meta {
    color: var(--mist);
    font-size: 13px;
    margin-top: 4px;
    font-family: monospace;
    direction: ltr;
}

/* ─── Settings Grid ─── */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--graphite);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: var(--transition);
}

.setting-item:hover {
    border-color: var(--ash);
}

.setting-item .info {
    font-size: 14px;
}

.setting-item .info small {
    display: block;
    color: var(--mist);
    font-size: 11px;
    margin-top: 2px;
}

/* ─── Tags ─── */
.tag {
    display: inline-block;
    padding: 4px 10px;
    background: var(--graphite);
    border: 1px solid var(--ash);
    border-radius: 6px;
    font-size: 12px;
    color: var(--mist);
    margin: 2px;
}

.tag.amber {
    background: var(--amber-soft);
    border-color: rgba(232, 181, 71, 0.2);
    color: var(--amber);
}

/* ─── Empty State ─── */
.empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--mist);
}

.empty .icon {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 12px;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--ash);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--smoke);
}

/* ─── Back Link ─── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--mist);
    font-size: 13px;
    margin-bottom: 16px;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--amber);
}

/* ─── Footer ─── */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--smoke);
    font-size: 12px;
    border-top: 1px solid var(--ash);
    margin-top: 40px;
}

/* ═══════════════════════════════════════════════════════════════
   Live layer — polling pill, animated counters, spotlight cards,
   live-flash rows, dismissible toast.
   Purely additive on top of the design system above; every page
   still renders and works correctly with JS disabled.
   ═══════════════════════════════════════════════════════════════ */

/* ─── Ambient aurora drift (subtle, respects reduced-motion) ─── */
body::before {
    background-size: 140% 140%, 140% 140%;
    animation: auroraDrift 24s ease-in-out infinite alternate;
}
@keyframes auroraDrift {
    0%   { background-position: 0% 0%, 100% 100%; }
    100% { background-position: 14% 10%, 86% 90%; }
}
@media (prefers-reduced-motion: reduce) {
    body::before { animation: none; }
}

/* ─── Card cursor spotlight (driven by --mx/--my from live.js) ─── */
.card { --mx: 50%; --my: 50%; }
.card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(240px circle at var(--mx) var(--my), rgba(232, 181, 71, 0.12), transparent 65%);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}
.card:hover::after { opacity: 1; }
.card:active { transform: translateY(-1px) scale(0.99); }

/* ─── Animated stat counters ─── */
.card .num {
    transition: color 0.3s ease;
    font-variant-numeric: tabular-nums;
}
.card .num.num-pop {
    animation: numPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: var(--amber);
}
@keyframes numPop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.16); }
    100% { transform: scale(1); }
}

/* ─── Live connection pill (injected into .topbar .brand by live.js) ─── */
.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-inline-start: 12px;
    padding: 5px 12px 5px 10px;
    border-radius: 999px;
    background: var(--graphite);
    border: 1px solid var(--ash);
    font-size: 11px;
    font-weight: 500;
    color: var(--mist);
    white-space: nowrap;
    transition: var(--transition);
}
.live-dot {
    position: relative;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--smoke);
    flex-shrink: 0;
}
.live-dot::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1px solid currentColor;
    opacity: 0;
}
.live-pill.live-connecting .live-dot {
    background: var(--mist);
    animation: liveConnectingPulse 1.1s ease-in-out infinite;
}
@keyframes liveConnectingPulse {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 1; }
}
.live-pill.live-ok {
    border-color: rgba(91, 193, 140, 0.25);
    color: var(--success);
    background: var(--success-soft);
}
.live-pill.live-ok .live-dot {
    background: var(--success);
    color: var(--success);
    animation: liveRing 2s ease-out infinite;
}
.live-pill.live-warn {
    border-color: rgba(232, 181, 71, 0.3);
    color: var(--amber);
    background: var(--amber-soft);
}
.live-pill.live-warn .live-dot { background: var(--amber); }
.live-pill.live-error {
    border-color: rgba(229, 83, 83, 0.3);
    color: var(--danger);
    background: var(--danger-soft);
}
.live-pill.live-error .live-dot { background: var(--danger); }
@keyframes liveRing {
    0%   { opacity: 0.55; transform: scale(1); }
    80%  { opacity: 0;    transform: scale(2.6); }
    100% { opacity: 0;    transform: scale(2.6); }
}

/* ─── Live-updated table rows & tables ─── */
tr.row-flash { animation: rowFlash 1.6s ease-out; }
@keyframes rowFlash {
    0%   { background: rgba(232, 181, 71, 0.22); }
    100% { background: transparent; }
}

.table-wrap[data-live-table] {
    position: relative;
    border-color: rgba(232, 181, 71, 0.14);
    animation: liveTableBreathe 4.5s ease-in-out infinite;
}
@keyframes liveTableBreathe {
    0%, 100% { box-shadow: 0 0 0 rgba(232, 181, 71, 0); }
    50%      { box-shadow: 0 0 0 3px rgba(232, 181, 71, 0.05); }
}
@media (prefers-reduced-motion: reduce) {
    .table-wrap[data-live-table] { animation: none; }
}

/* ─── Gentle "in progress" pulse on live status badges ─── */
.badge.pending, .badge.processing {
    animation: badgePulse 1.8s ease-in-out infinite;
}
@keyframes badgePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(232, 181, 71, 0.25); }
    50%      { box-shadow: 0 0 0 4px rgba(232, 181, 71, 0); }
}

/* ─── Flash message → dismissible toast with auto-close bar ─── */
.flash {
    position: relative;
    overflow: hidden;
    padding-inline-end: 40px;
}
.flash-close {
    position: absolute;
    top: 8px;
    left: 10px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    transition: var(--transition);
}
.flash-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
}
.flash-bar {
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    height: 2px;
    background: currentColor;
    opacity: 0.5;
    animation: flashShrink 5.2s linear forwards;
    transform-origin: right;
}
@keyframes flashShrink {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}
.flash.flash-out { animation: flashOut 0.25s ease forwards; }
@keyframes flashOut {
    to { opacity: 0; transform: translateY(-8px); }
}

/* ─── Small interaction polish ─── */
.btn { position: relative; }
.btn:active { transform: scale(0.97); }
a:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   Live layer — mobile hardening
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .topbar .brand {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
    }
    .topbar .brand > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .live-pill {
        margin-inline-start: 8px;
        flex-shrink: 0;
    }
}
@media (max-width: 560px) {
    .live-pill .live-text { display: none; }
    .live-pill {
        padding: 6px;
        margin-inline-start: 6px;
    }
    .live-dot { width: 8px; height: 8px; }
}
@media (max-width: 420px) {
    .topbar .brand .logo { width: 30px; height: 30px; font-size: 15px; }
    .topbar .brand > span { font-size: 15px; }
    .card { padding: 16px; }
    .card .num { font-size: 26px; }
    .card .icon { width: 36px; height: 36px; font-size: 18px; margin-bottom: 10px; }
}
