/* Echo Panel — Dark theme, Blendmedia design language */

@import url('https://api.fontshare.com/v2/css?f[]=clash-display@600,700&f[]=satoshi@400,500,600,700&display=swap');

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #0f0f18;
    --bg-card: #12121c;
    --bg-card-hover: #161625;
    --bg-input: #1a1a2a;
    --surface: #1e1e30;

    --blue: #2563EB;
    --blue-light: #3B82F6;
    --blue-deep: #1D4ED8;
    --blue-glow: rgba(37, 99, 235, 0.15);
    --blue-subtle: rgba(37, 99, 235, 0.08);

    --teal: #0D8F7F;
    --teal-light: #12B89E;
    --coral: #E8664A;
    --gold: #F5A623;

    --text-primary: #e8e8f0;
    --text-secondary: #8888a8;
    --text-muted: #5a5a7a;

    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --orange: #f97316;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-blue: 0 2px 12px rgba(37, 99, 235, 0.25);

    --transition: all 0.2s cubic-bezier(.16, 1, .3, 1);
    --font-display: 'Clash Display', sans-serif;
    --font-body: 'Satoshi', sans-serif;
}

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

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* ── Layout ── */

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

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--blue-subtle);
    padding: 1.5rem 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid var(--blue-subtle);
    margin-bottom: 1rem;
}

.sidebar-brand h1 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--blue-light), var(--teal-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-brand span {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--blue-subtle);
}

.nav-item.active {
    color: var(--blue-light);
    background: var(--blue-glow);
    border-left-color: var(--blue);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.main {
    flex: 1;
    margin-left: 240px;
    padding: 2rem;
    max-width: 1200px;
}

/* ── Page Header ── */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
}

/* ── Stats Grid ── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--blue-glow);
    box-shadow: var(--shadow-card);
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
}

.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.blue { color: var(--blue-light); }
.stat-value.gold { color: var(--gold); }

/* ── Cards ── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    max-width: 100%;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--blue-subtle);
}

.card-header h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
}

/* ── Task List ── */

.task-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto auto;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--blue-subtle);
    transition: var(--transition);
}

.task-item:last-child { border-bottom: none; }

.task-item:hover {
    background: var(--bg-card-hover);
}

.task-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.task-schedule {
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--teal-light);
    background: rgba(13, 143, 127, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.task-model {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    background: var(--blue-glow);
    color: var(--blue-light);
}

.task-notify {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
}

.task-notify.you { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.task-notify.agent { background: rgba(234, 179, 8, 0.15); color: var(--yellow); }
.task-notify.both { background: rgba(59, 130, 246, 0.15); color: var(--blue-light); }

.task-actions {
    display: flex;
    gap: 0.4rem;
}

/* ── Toggle Switch ── */

.toggle {
    position: relative;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.toggle input { display: none; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border-radius: 11px;
    transition: var(--transition);
    border: 1px solid var(--blue-subtle);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    left: 2px;
    top: 2px;
    transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--blue);
    border-color: var(--blue);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(18px);
    background: white;
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue), var(--blue-light));
    color: white;
    box-shadow: var(--shadow-blue);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 32px rgba(37, 99, 235, 0.35);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--blue-subtle);
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--blue-subtle);
}

.btn-icon {
    padding: 0.4rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--blue-subtle);
    border-color: var(--blue-subtle);
}

.btn-icon.play:hover { color: var(--green); }
.btn-icon.edit:hover { color: var(--blue-light); }
.btn-icon.delete:hover { color: var(--red); }

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

/* ── Runs / Log Table ── */

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

.runs-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--blue-subtle);
}

.runs-table td {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--blue-subtle);
    vertical-align: top;
}

.runs-table tr:hover td {
    background: var(--bg-card-hover);
}

.runs-table tr { cursor: pointer; }

/* ── Status Badges ── */

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status.completed { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.status.running { background: rgba(59, 130, 246, 0.15); color: var(--blue-light); }
.status.failed { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.status.timeout { background: rgba(249, 115, 22, 0.15); color: var(--orange); }
.status.error { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.status.pending { background: rgba(136, 136, 168, 0.15); color: var(--text-secondary); }

.status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Modal ── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h3 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.65rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-glow);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ── Run Detail Panel ── */

.run-detail {
    padding: 1.25rem;
}

.run-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.run-meta {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.run-meta span {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.run-output {
    background: var(--bg-primary);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-sm);
    padding: 1rem;
    font-family: monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 500px;
    overflow-y: auto;
    color: var(--text-primary);
}

.run-output.stderr {
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--red);
}

/* ── Cron View ── */

.cron-content {
    background: var(--bg-primary);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-sm);
    padding: 1rem;
    font-family: monospace;
    font-size: 0.82rem;
    line-height: 1.8;
    white-space: pre-wrap;
    color: var(--text-secondary);
}

.cron-content .comment { color: var(--teal); }
.cron-content .schedule { color: var(--blue-light); }

/* ── Filter Bar ── */

.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
    padding: 0.45rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.85rem;
}

/* ── Pagination ── */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 1rem;
}

.pagination-info {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Toast ── */

.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--blue-subtle);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow-hover);
    animation: slideIn 0.3s cubic-bezier(.16, 1, .3, 1);
    min-width: 250px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue-light); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Mobile Bottom Nav ── */

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg-secondary);
    border-top: 1px solid var(--blue-subtle);
    backdrop-filter: blur(20px);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.6rem 0.5rem 0.5rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
}

.mobile-tab span {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.mobile-tab.active {
    color: var(--blue-light);
}

.mobile-tab:hover {
    color: var(--text-primary);
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .mobile-nav { display: flex; }
    .sidebar { display: none; }
    .main { margin-left: 0; padding: 0.75rem; padding-bottom: 5rem; }

    /* Stats */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
    .stat-card { padding: 0.85rem; }
    .stat-value { font-size: 1.4rem; }
    .stat-label { font-size: 0.68rem; }

    /* Page header */
    .page-header { flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
    .page-header h2 { font-size: 1.2rem; width: 100%; }

    /* Tasks */
    .task-item {
        grid-template-columns: auto 1fr auto;
        padding: 0.75rem 0.75rem;
        gap: 0.6rem;
    }
    .task-schedule, .task-model, .task-notify { display: none; }
    .task-name { font-size: 0.88rem; }
    .task-item > div > div:last-child { font-size: 0.72rem; }
    .task-actions { gap: 0.2rem; }
    .btn-icon { padding: 0.5rem; }

    /* Runs table - card layout on mobile */
    .runs-table thead { display: none; }
    .runs-table, .runs-table tbody, .runs-table tr, .runs-table td {
        display: block;
        width: 100%;
    }
    .runs-table tr {
        padding: 0.75rem;
        border-bottom: 1px solid var(--blue-subtle);
        position: relative;
    }
    .runs-table td {
        padding: 0.15rem 0;
        border: none;
        font-size: 0.82rem;
    }
    .runs-table td:first-child {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }
    .runs-table td:nth-child(3),
    .runs-table td:nth-child(5) { display: none; }

    /* Run detail */
    .run-detail { padding: 0.5rem; }
    .run-meta { gap: 0.5rem; font-size: 0.72rem; }
    .run-output { font-size: 0.75rem; padding: 0.75rem; max-height: 350px; }

    /* Modal */
    .modal { width: 95%; padding: 1.25rem; margin: 0.5rem; max-height: 90vh; }
    .modal h3 { font-size: 1.05rem; margin-bottom: 1rem; }
    .form-group input, .form-group textarea, .form-group select { font-size: 16px; padding: 0.6rem 0.75rem; }
    .form-row { grid-template-columns: 1fr; }
    .modal-actions { flex-direction: column; }
    .modal-actions .btn { width: 100%; justify-content: center; }

    /* Filter */
    .filter-bar { flex-direction: column; align-items: stretch; gap: 0.5rem; }
    .filter-bar select, .filter-bar input { width: 100%; font-size: 16px; }

    /* Cron */
    .cron-content { font-size: 0.7rem; padding: 0.75rem; line-height: 1.6; overflow-x: auto; }

    /* Cards */
    .card { border-radius: var(--radius-sm); }
    .card-header { padding: 0.75rem; }
    .card-header h3 { font-size: 0.9rem; }
    .card-body { padding: 0.75rem; }

    /* Pagination */
    .pagination { padding: 0.75rem; gap: 0.25rem; }
    .pagination-info { font-size: 0.72rem; }

    /* Toast */
    .toast-container { top: 0.75rem; right: 0.75rem; left: 0.75rem; }
    .toast { min-width: auto; font-size: 0.82rem; }

    /* Empty state */
    .empty-state { padding: 2rem 1rem; font-size: 0.85rem; }
}

/* ── Scrollbar ── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--blue-subtle); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Empty State ── */

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.3;
}

/* ── Loading ── */

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--blue-subtle);
    border-top-color: var(--blue-light);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
