/* ── VARIABLES ────────────────────────────────────────── */
:root {
    --bg-base:        #0c0c10;
    --bg-surface:     #13131a;
    --bg-card:        #18181f;
    --bg-card-hover:  #1e1e28;
    --bg-panel:       #0f0f15;
    --bg-topbar:      #111118;

    --border:         #252530;
    --border-subtle:  #1a1a22;

    --text-primary:   #e2e2ee;
    --text-secondary: #7878a0;
    --text-muted:     #44445a;

    --accent:         #7c5af5;
    --accent-hover:   #9170f8;
    --accent-glow:    rgba(124, 90, 245, 0.25);

    --status-idle:       #33334a;
    --status-running:    #f59c0a;
    --status-success:    #22c55e;
    --status-error:      #ef4444;
    --status-background: #06b6d4;

    --header-h: 52px;
    --panel-h: 65vh;
    --font:     'Inter', system-ui, sans-serif;
    --mono:     'JetBrains Mono', 'Courier New', monospace;
    --radius:   10px;
    --ease:     cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── RESET ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── HEADER ───────────────────────────────────────────── */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: rgba(12, 12, 16, 0.9);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    gap: 16px;
}

/* Brand */
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand-icon { display: flex; }

.brand-name {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

.brand-accent { color: var(--accent); }

/* Live indicator */
.header-center {
    display: flex;
    align-items: center;
    gap: 7px;
}

.live-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--status-success);
    flex-shrink: 0;
    animation: pulse-live 2.5s infinite;
}

.live-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

@keyframes pulse-live {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
    60%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

/* Auth field */
.header-auth { display: flex; align-items: center; }

.auth-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 12px;
    transition: border-color 0.2s;
}

.auth-wrapper:focus-within { border-color: var(--accent); }

.auth-wrapper.unlocked { border-color: var(--status-success); }

.lock-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color 0.25s;
}

.auth-wrapper.unlocked .lock-icon { color: var(--status-success); }

.key-input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--mono);
    font-size: 0.78rem;
    width: 130px;
    caret-color: var(--accent);
}

.key-input::placeholder { color: var(--text-muted); }

.auth-indicator {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.3s;
}

.auth-indicator.ok  { background: var(--status-success); }
.auth-indicator.err { background: var(--status-error); }

/* ── MAIN CONTENT ─────────────────────────────────────── */
.main-content {
    margin-top: var(--header-h);
    padding: 22px 24px 20px;
    transition: padding-bottom 0.45s var(--ease);
}

.main-content.panel-open {
    padding-bottom: calc(var(--panel-h) + 20px);
}

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

/* ── CATEGORY SECTION ─────────────────────────────────── */
.category-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.cat-icon { font-size: 0.9rem; line-height: 1; }

.category-title {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* ── MODULE CARD ──────────────────────────────────────── */
.module-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.module-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 10px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    flex: 1 1 64px;
    min-width: 64px;
    transition: background 0.2s, border-color 0.2s;
}

.module-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border);
}

/* ── DOT (semaphore) ──────────────────────────────────── */
.dot {
    display: block;
    width: 11px; height: 11px;
    border-radius: 50%;
    background: var(--status-idle);
    transition: background-color 0.35s;
    flex-shrink: 0;
}

.module-name {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
}

.module-time {
    font-size: 0.6rem;
    font-family: var(--mono);
    color: var(--text-muted);
}

/* Status classes */
.status-idle       { background-color: var(--status-idle); }
.status-running    { background-color: var(--status-running);    animation: dot-pulse 1.4s infinite; }
.status-success    { background-color: var(--status-success); }
.status-error      { background-color: var(--status-error); }
.status-background { background-color: var(--status-background); animation: dot-pulse-slow 3.5s infinite; }

@keyframes dot-pulse {
    0%, 100% { box-shadow: 0 0 0 0   rgba(245,156,10,0.7); }
    50%       { box-shadow: 0 0 0 5px rgba(245,156,10,0);   }
}

@keyframes dot-pulse-slow {
    0%, 100% { box-shadow: 0 0 0 0   rgba(6,182,212,0.7); }
    50%       { box-shadow: 0 0 0 5px rgba(6,182,212,0);   }
}

/* ── CONTROL PANEL ────────────────────────────────────── */
.control-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--panel-h);
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.45s var(--ease);
    z-index: 100;
}

.control-panel.visible { transform: translateY(0); }

/* Top bar: tabs + actions */
.panel-topbar {
    display: flex;
    align-items: center;
    height: 42px;
    flex-shrink: 0;
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border);
    padding: 0 14px;
    gap: 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.panel-topbar::-webkit-scrollbar { display: none; }

/* Tabs */
.panel-tabs {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    text-transform: uppercase;
    white-space: nowrap;
}

.tab-btn:hover { color: var(--text-primary); background: var(--bg-card); }

.tab-btn.active {
    color: var(--accent);
    background: var(--bg-card);
}

/* Action bar */
.action-bar {
    display: flex;
    align-items: center;
    gap: 0;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    padding-left: 8px;
    border-left: 1px solid var(--border-subtle);
}

.action-bar::-webkit-scrollbar { display: none; }

.action-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    border-right: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.action-group:last-child { border-right: none; }

.action-group-label {
    font-size: 0.58rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-right: 3px;
    white-space: nowrap;
}

.action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.7rem;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.action-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px var(--accent-glow);
}

.action-btn:active { transform: translateY(0) scale(0.97); }

.action-btn--dev { color: #f59c0a; border-color: rgba(245,156,10,0.3); }
.action-btn--dev:hover { background: #f59c0a; border-color: #f59c0a; color: #000; box-shadow: 0 3px 10px rgba(245,156,10,0.3); }

.action-btn--adm { color: #ef4444; border-color: rgba(239,68,68,0.3); }
.action-btn--adm:hover { background: #ef4444; border-color: #ef4444; color: #fff; box-shadow: 0 3px 10px rgba(239,68,68,0.25); }

/* Panel body */
.panel-body {
    flex: 1;
    overflow: hidden;
}

.panel-pane {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
}

.panel-pane.active { display: flex; }

/* Console */
#log-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px 18px 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-all;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

#log-container::-webkit-scrollbar { width: 5px; }
#log-container::-webkit-scrollbar-track { background: transparent; }
#log-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#log-container > div {
    padding: 1px 6px;
    border-radius: 3px;
    margin-bottom: 1px;
}

/* Scheduler */
#schedule-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 18px 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

#schedule-container::-webkit-scrollbar { width: 5px; }
#schedule-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.next-task {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 10px;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.scheduled-task {
    padding: 5px 0;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.scheduled-task:last-child { border-bottom: none; }
.scheduled-task.inactive { color: var(--text-muted); font-style: italic; }

/* ── TOAST ────────────────────────────────────────────── */
.toast {
    position: fixed;
    top: calc(var(--header-h) + 12px);
    right: 20px;
    background: var(--accent);
    color: #fff;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    z-index: 300;
    animation: toast-in 0.3s var(--ease) forwards, toast-out 0.4s var(--ease) 3.2s forwards;
}

@keyframes toast-in  { from { opacity:0; transform: translateY(-8px); } to { opacity:1; transform: translateY(0); } }
@keyframes toast-out { from { opacity:1; transform: translateY(0);    } to { opacity:0; transform: translateY(-8px); } }

/* ── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 960px) {
    .grid-container { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .action-group-label { display: none; }
    .key-input { width: 90px; }
}

@media (max-width: 640px) {
    .main-content { padding: 14px 12px 12px; }
    .brand-name { font-size: 0.95rem; }
    .grid-container { grid-template-columns: 1fr 1fr; }
    .header-center { display: none; }
}

/* ════════════════════════════════════════════════════════
 * V2 — dashboard rebuild (console persistente + schedules)
 * ════════════════════════════════════════════════════════ */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 14px;
    padding: calc(var(--header-h) + 14px) 16px 16px;
    min-height: 100vh;
    align-items: start;
}

.layout-left  { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.layout-right { position: sticky; top: calc(var(--header-h) + 14px); height: calc(100vh - var(--header-h) - 28px); }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: linear-gradient(180deg, rgba(124,90,245,0.04), transparent);
    flex-wrap: wrap;
    gap: 10px;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: var(--text-primary);
}

.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Status pills */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    padding: 12px 16px;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    font-size: 0.78rem;
}

.status-pill .dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--status-idle);
    flex-shrink: 0;
}

.status-pill-name { flex: 1; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill-time { font-family: var(--mono); color: var(--text-secondary); font-size: 0.72rem; flex-shrink: 0; }

.dot.status-running    { background: var(--status-running); box-shadow: 0 0 8px var(--status-running); }
.dot.status-success    { background: var(--status-success); }
.dot.status-error      { background: var(--status-error);   box-shadow: 0 0 8px var(--status-error); }
.dot.status-background { background: var(--status-background); }
.dot.status-idle       { background: var(--status-idle); }

/* Buttons & inputs */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: 6px;
    font-family: var(--font);
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover { background: var(--bg-card-hover); }
.btn[disabled] { opacity: 0.5; cursor: wait; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border-subtle); color: var(--text-secondary); }
.btn-sm { padding: 4px 8px; font-size: 0.72rem; }

.input {
    background: var(--bg-base);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 5px;
    padding: 6px 10px;
    font-family: var(--mono);
    font-size: 0.78rem;
    min-width: 0;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-sm { width: 80px; }

.toggle {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.75rem; color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.toggle input { accent-color: var(--accent); }

/* Add-form */
.add-form { padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); background: var(--bg-surface); }
.add-form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-form-msg { margin-top: 8px; font-family: var(--mono); font-size: 0.74rem; color: var(--text-secondary); min-height: 16px; }

/* Schedule table */
.table-wrap { overflow-x: auto; }

.sched-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.sched-table thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1;
}

.sched-table tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.sched-table tbody tr:hover { background: var(--bg-card-hover); }

.empty-row {
    text-align: center;
    color: var(--text-muted);
    padding: 28px 12px !important;
    font-style: italic;
}

.cell-func { display: flex; flex-direction: column; }
.func-name { color: var(--text-primary); font-weight: 500; }
.func-tech { font-family: var(--mono); color: var(--text-muted); font-size: 0.68rem; }

.trigger-pill {
    display: inline-block;
    padding: 2px 7px;
    background: rgba(124,90,245,0.15);
    color: #b297ff;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 0.7rem;
}

.hf-tag {
    display: inline-block;
    padding: 1px 5px;
    background: var(--status-running);
    color: #000;
    border-radius: 3px;
    font-size: 0.65rem;
    margin-left: 4px;
    font-weight: 600;
}

.exec-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 500;
}
.exec-status.ok   { background: rgba(34,197,94,0.18); color: #86efac; }
.exec-status.bad  { background: rgba(239,68,68,0.18); color: #fca5a5; }
.exec-status.none { background: var(--bg-surface); color: var(--text-muted); }

.col-actions { white-space: nowrap; text-align: right; }

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 5px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-left: 4px;
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.icon-btn.run-btn:hover { background: var(--status-success); color: #000; border-color: var(--status-success); }
.icon-btn.del-btn:hover { background: var(--status-error);   color: #000; border-color: var(--status-error); }

/* Console */
.console-card {
    height: 100%;
}

.log-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: var(--mono);
    font-size: 0.74rem;
    line-height: 1.55;
    background: var(--bg-panel);
}

.log-container > div {
    padding: 2px 6px;
    margin-bottom: 1px;
    border-radius: 3px;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Responsive */
@media (max-width: 1100px) {
    .layout { grid-template-columns: 1fr; }
    .layout-right {
        position: static;
        height: 60vh;
    }
}

@media (max-width: 640px) {
    .layout { padding: calc(var(--header-h) + 10px) 8px 8px; gap: 8px; }
    .status-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .sched-table thead th { padding: 8px 6px; font-size: 0.66rem; }
    .sched-table tbody td { padding: 7px 6px; }
}

