/* ============================================
   FIPK Scheduler Dashboard — Styles
   Dual-Theme System (Dark / Light), Push Sidebar, Inter Font
   ============================================ */

/* ---------- Dark Theme (Default) ---------- */
:root {
    --bg-primary: #111111;
    --bg-secondary: #1a1a1a;
    --bg-surface: #222222;
    --bg-surface-hover: #2a2a2a;
    --bg-widget: rgba(26, 26, 26, 0.92);
    --bg-input: rgba(255, 255, 255, 0.06);

    --text-primary: #f0f0ff;
    --text-secondary: #9d9dc0;
    --text-muted: #6b6b8d;
    --text-accent: #a78bfa;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-active: rgba(139, 92, 246, 0.4);

    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-glow: rgba(139, 92, 246, 0.2);

    --green: #4ade80;
    --green-glow: rgba(74, 222, 128, 0.12);
    --red: #f87171;
    --red-glow: rgba(248, 113, 113, 0.12);
    --yellow: #fbbf24;
    --blue: #60a5fa;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition-fast: 150ms ease;
}

/* ---------- Light Theme ---------- */
[data-theme="light"] {
    --bg-primary: #f5f5f0;
    --bg-secondary: #ffffff;
    --bg-surface: #f0f0eb;
    --bg-surface-hover: #e8e8e3;
    --bg-widget: rgba(255, 255, 255, 0.92);
    --bg-input: rgba(0, 0, 0, 0.04);

    --text-primary: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-muted: #999999;
    --text-accent: #6b7a30;

    --border-color: rgba(0, 0, 0, 0.08);
    --border-active: rgba(124, 140, 60, 0.4);

    --accent: #7c8c3c;
    --accent-hover: #6b7a30;
    --accent-glow: rgba(124, 140, 60, 0.15);

    --green: #2d8a4e;
    --green-glow: rgba(45, 138, 78, 0.1);
    --red: #d14343;
    --red-glow: rgba(209, 67, 67, 0.1);
    --yellow: #b8860b;
    --blue: #3572b0;
}

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

html {
    font-size: 14px;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ========== Header ========== */
.sch-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background 0.3s ease;
}

.sch-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sch-logo {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 3px;
    background: linear-gradient(135deg, var(--accent), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sch-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
}

.sch-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.sch-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sch-clock {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-input);
    border-radius: 9999px;
    padding: 3px;
    border: 1px solid var(--border-color);
}

.theme-toggle button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
    padding: 0;
}

.theme-toggle button.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ---------- Push Sidebar Layout ---------- */
.sch-app-layout {
    display: flex;
    width: 100%;
    min-height: calc(100vh - 57px);
    position: relative;
    overflow-x: hidden;
}

.sidebar-drawer {
    position: relative;
    width: 300px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
    z-index: 10;
}

.sidebar-drawer.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    border-right-color: transparent !important;
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    width: 300px;
    min-width: 300px;
    box-sizing: border-box;
}

.sidebar-title {
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--accent);
}

.sidebar-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 300px;
    min-width: 300px;
    box-sizing: border-box;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 4px;
    padding: 0 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    width: 100%;
    text-align: left;
    font-family: var(--font);
}

.sidebar-item:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
}

.sidebar-item.active {
    background: var(--bg-surface);
    border-color: var(--border-active);
}

.sidebar-item.highlight {
    background: var(--accent-glow);
    border-color: var(--border-active);
}

.sidebar-item-icon {
    font-size: 1.1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    flex-shrink: 0;
}

.sidebar-item-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-item-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-item-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sch-app-main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ========== Buttons ========== */
.sch-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s;
}

.sch-btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.sch-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.sch-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.sch-btn-icon:hover:not(:disabled) {
    background: var(--bg-surface-hover);
    border-color: var(--border-active);
}

.sch-btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.sch-btn-run {
    color: var(--green);
}

.sch-btn-run:hover:not(:disabled) {
    background: var(--green-glow);
    border-color: var(--green);
}

.sch-btn-pause {
    color: var(--yellow);
}

.sch-btn-pause:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: var(--yellow);
}

.sch-btn-resume {
    color: var(--green);
}

.sch-btn-resume:hover {
    background: var(--green-glow);
    border-color: var(--green);
}

/* ========== Stats Bar ========== */
.sch-stats-bar {
    display: flex;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.sch-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    flex: 1;
}

.sch-stat-icon {
    font-size: 1.2rem;
}

.sch-stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sch-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ========== Main Content ========== */
.sch-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sch-section {
    background: var(--bg-widget);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.sch-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sch-section-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.sch-auto-refresh {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 3px 10px;
    background: var(--bg-input);
    border-radius: 20px;
}

/* ========== Select ========== */
.sch-select {
    padding: 5px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.8rem;
    outline: none;
}

.sch-select:focus {
    border-color: var(--accent);
}

.sch-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ========== Jobs Table ========== */
.sch-table-wrapper {
    overflow-x: auto;
}

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

.sch-table thead th {
    padding: 10px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.sch-table tbody tr {
    transition: background 0.15s;
}

.sch-table tbody tr:hover {
    background: var(--bg-surface-hover);
}

.sch-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--border-color);
}

.sch-table td {
    padding: 12px 14px;
    font-size: 0.85rem;
    vertical-align: middle;
}

.col-icon {
    width: 40px;
    font-size: 1.2rem;
    text-align: center;
}

.col-name strong {
    display: block;
    font-weight: 600;
}

.col-name small {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-family: monospace;
}

.col-schedule {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.col-duration code {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 3px;
}

.col-last,
.col-next {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.col-actions {
    display: flex;
    gap: 6px;
}

/* Disabled row */
.disabled-row {
    opacity: 0.4;
}

.disabled-row:hover {
    opacity: 0.6;
}

/* Error row */
.error-row {
    background: rgba(239, 68, 68, 0.05);
}

.error-detail-row td {
    padding: 0 14px 12px;
}

.sch-error-detail {
    font-size: 0.72rem;
    color: var(--red);
    background: var(--red-glow);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    max-height: 120px;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ========== Status Badge ========== */
.sch-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.sch-badge.success {
    background: var(--green-glow);
    color: var(--green);
}

.sch-badge.error {
    background: var(--red-glow);
    color: var(--red);
}

.sch-badge.pending {
    background: var(--bg-input);
    color: var(--text-muted);
}

/* ========== History List ========== */
.sch-history-list {
    max-height: 400px;
    overflow-y: auto;
}

.sch-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    transition: background 0.15s;
}

.sch-history-item:hover {
    background: var(--bg-surface-hover);
}

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

.sch-history-item.error {
    background: rgba(239, 68, 68, 0.03);
}

.sch-history-time {
    min-width: 70px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.sch-history-icon {
    font-size: 1.1rem;
}

.sch-history-name {
    min-width: 110px;
    font-weight: 500;
}

.sch-history-status {
    font-size: 0.9rem;
}

.sch-history-duration {
    min-width: 50px;
}

.sch-history-duration code {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 3px;
}

.sch-history-msg {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========== Empty & Loading ========== */
.sch-loading,
.sch-empty {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ========== Toast ========== */
.sch-toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.sch-toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    font-size: 0.85rem;
    animation: toastSlideIn 0.3s ease;
    max-width: 400px;
}

.sch-toast.success {
    border-left: 3px solid var(--green);
}

.sch-toast.error {
    border-left: 3px solid var(--red);
}

.sch-toast.info {
    border-left: 3px solid var(--blue);
}

.sch-toast button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

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

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sch-header {
        padding: 10px 16px;
    }

    .sch-title {
        display: none;
    }

    .sch-divider {
        display: none;
    }

    .sch-btn span {
        display: none;
    }

    .sch-stats-bar {
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 8px;
    }

    .sch-stat {
        flex: 1 1 45%;
        min-width: 0;
    }

    .sch-main {
        padding: 16px;
    }

    .col-next {
        display: none;
    }

    .sch-history-msg {
        display: none;
    }
}

@media (max-width: 480px) {
    .sch-stat {
        flex: 1 1 100%;
    }

    .col-schedule {
        display: none;
    }

    .col-duration {
        display: none;
    }
}