/* ============================================================
   Crontab Visual Scheduler — Premium Dark Theme
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Core palette */
    --primary: #6C63FF;
    --primary-hover: #7B73FF;
    --primary-glow: rgba(108, 99, 255, 0.25);
    --secondary: #3B82F6;
    --accent: #22D3EE;
    --danger: #EF4444;
    --danger-hover: #F87171;
    --success: #10B981;
    --warning: #F59E0B;

    /* Background layers */
    --bg-base: #0A0A12;
    --bg-surface: #12121E;
    --bg-elevated: #1A1A2E;
    --bg-hover: #222238;
    --bg-active: #2A2A42;

    /* Text */
    --text-primary: #F0F0F5;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --text-inverse: #0A0A12;

    /* Borders */
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --border-focus: var(--primary);

    /* Glassmorphism */
    --glass-bg: rgba(18, 18, 30, 0.8);
    --glass-border: rgba(255, 255, 255, 0.08);

    /* Dimensions */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--primary-glow);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Calendar */
    --cell-size: 28px;
    --time-label-width: 60px;
    --day-header-height: 40px;

    /* Schedule colors */
    --sched-1: #6C63FF;
    --sched-2: #22D3EE;
    --sched-3: #F59E0B;
    --sched-4: #10B981;
    --sched-5: #EF4444;
    --sched-6: #EC4899;
    --sched-7: #8B5CF6;
    --sched-8: #F97316;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* Background pattern */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 99, 255, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(59, 130, 246, 0.08), transparent);
    pointer-events: none;
    z-index: 0;
}

/* --- Screen reader only --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* --- App Container --- */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0;
    gap: 16px;
    flex-wrap: wrap;
}

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

.logo {
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

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

.timezone-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    transition: border-color var(--transition-fast);
}

.timezone-selector:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}

.timezone-selector .icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.timezone-selector select {
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    max-width: 200px;
}

.timezone-selector select option {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

/* ============================================================
   Toolbar
   ============================================================ */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.schedule-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-sm), 0 0 12px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), 0 0 20px var(--primary-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-ghost {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border);
}

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

.btn-danger {
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-hover);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-icon.btn-danger:hover {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger-hover);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

/* ============================================================
   Content Layout
   ============================================================ */
.content-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    padding-bottom: 40px;
}

/* ============================================================
   Calendar Grid
   ============================================================ */
.calendar-section {
    min-width: 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: var(--time-label-width) repeat(7, 1fr);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

/* Time labels */
.time-labels {
    display: flex;
    flex-direction: column;
}

.corner-cell {
    height: var(--day-header-height);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.time-label {
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    border-right: 1px solid var(--border);
    font-family: var(--font-mono);
}

.time-label:nth-child(even) {
    color: transparent;
}

/* Day columns */
.day-column {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.day-column:last-child {
    border-right: none;
}

.day-header {
    height: var(--day-header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    user-select: none;
    letter-spacing: 0.02em;
}

.day-header.today {
    color: var(--primary);
    background: linear-gradient(180deg, rgba(108, 99, 255, 0.1), transparent);
}

/* Calendar cells */
.calendar-cell {
    height: var(--cell-size);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
}

.calendar-cell:hover {
    background: var(--bg-hover);
}

.calendar-cell.hour-start {
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

.calendar-cell.hour-end {
    border-bottom-color: var(--border);
}

.calendar-cell.selected {
    position: relative;
}

.calendar-cell.selected::after {
    content: '';
    position: absolute;
    inset: 1px;
    border-radius: 3px;
    opacity: 0.7;
    background: var(--cell-color, var(--primary));
    animation: cellPop 200ms var(--transition-spring);
}

.calendar-cell.selecting {
    background: rgba(108, 99, 255, 0.15);
}

@keyframes cellPop {
    0% {
        transform: scale(0.6);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 0.7;
    }
}

.calendar-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sidebar-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 600;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex: 1;
}

.panel-header .panel-title {
    padding: 0;
    border-bottom: none;
}

/* Schedule List */
.schedule-list {
    max-height: 500px;
    overflow-y: auto;
}

.schedule-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border);
    user-select: none;
}

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

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

.schedule-item.active {
    background: var(--bg-active);
}

.schedule-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

.schedule-info {
    flex: 1;
    min-width: 0;
}

.schedule-info .name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-info .cron {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 40px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state p {
    font-weight: 500;
    font-size: 0.9rem;
}

.empty-state span {
    font-size: 0.78rem;
    opacity: 0.7;
}

/* Schedule Detail */
.detail-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.field-input {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    transition: all var(--transition-fast);
    outline: none;
}

.field-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.field-input.mono {
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.cron-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.cron-expression {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 500;
    color: var(--primary);
    letter-spacing: 0.05em;
}

.natural-lang {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    border-left: 3px solid var(--primary);
}

.next-runs {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 200px;
    overflow-y: auto;
}

.next-runs li {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 5px 10px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
}

.next-runs li::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    animation: fadeIn 200ms ease forwards;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 520px;
    animation: slideUp 250ms var(--transition-spring);
}

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

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
}

.field-textarea {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition-fast);
    line-height: 1.6;
}

.field-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(16px) scale(0.97);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

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

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.85rem;
    color: var(--text-primary);
    animation: toastSlide 300ms var(--transition-spring);
    max-width: 360px;
}

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

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

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

.toast-exit {
    animation: toastExit 200ms ease forwards;
}

@keyframes toastSlide {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

@keyframes toastExit {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

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

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

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

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

/* ============================================================
   Responsive Design
   ============================================================ */
@media (max-width: 1024px) {
    .content-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        order: -1;
    }

    .calendar-grid {
        overflow-x: auto;
    }
}

@media (max-width: 640px) {
    .app-container {
        padding: 0 12px;
    }

    .app-header {
        padding: 14px 0;
    }

    .app-header h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        display: none;
    }

    .toolbar-left {
        gap: 4px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .btn svg {
        width: 14px;
        height: 14px;
    }

    :root {
        --cell-size: 22px;
        --time-label-width: 44px;
        --day-header-height: 34px;
    }

    .time-label {
        font-size: 0.6rem;
        padding-right: 4px;
    }

    .day-header {
        font-size: 0.72rem;
    }
}