/* =========================================
   SmartApp — Main Stylesheet
   Following DESIGN_GUIDELINES.md
   ========================================= */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap');

/* --- CSS Variables --- */
:root {
    --color-brand: #6366f1;
    --color-brand-light: #818cf8;
    --color-brand-dark: #4f46e5;

    --color-success: #10b981;
    --color-info: #3b82f6;
    --color-warning: #f59e0b;
    --color-danger: #f43f5e;

    --sidebar-width: 256px;
    --sidebar-collapsed: 80px;
    --header-height: 64px;

    /* Light mode (defaults) */
    --bg-body: #ffffff;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f8fafc;
    --border: #e5e7eb;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);

    /* Backwards-compat aliases (do not use in new code) */
    --bg-glass: var(--bg-surface);
    --bg-glass-hover: var(--bg-surface-elevated);
    --border-glass: var(--border);

    /* Log viewer */
    --log-bg: #1e1e2e;
    --log-text: #cdd6f4;
    --log-error: #f38ba8;
    --log-success: #a6e3a1;
    --log-warning: #f9e2af;
}

/* Dark mode (system preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #0b0d10;
        --bg-surface: #14171c;
        --bg-surface-elevated: #1b1f25;
        --border: #2a2f37;
        --text-primary: #ffffff;
        --text-secondary: #cbd5e1;
        --text-muted: #8a93a3;
        --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --log-bg: #0d1117;
        --log-text: #c9d1d9;
        --log-error: #f85149;
        --log-success: #3fb950;
        --log-warning: #d29922;
    }
}

[data-theme="dark"] {
    --bg-body: #0b0d10;
    --bg-surface: #14171c;
    --bg-surface-elevated: #1b1f25;
    --border: #2a2f37;
    --text-primary: #ffffff;
    --text-secondary: #cbd5e1;
    --text-muted: #8a93a3;
    --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --log-bg: #0d1117;
    --log-text: #c9d1d9;
    --log-error: #f85149;
    --log-success: #3fb950;
    --log-warning: #d29922;
}

[data-theme="light"] {
    --bg-body: #ffffff;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f8fafc;
    --border: #e5e7eb;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --log-bg: #1e1e2e;
    --log-text: #cdd6f4;
    --log-error: #f38ba8;
    --log-success: #a6e3a1;
    --log-warning: #f9e2af;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

[data-theme="dark"] body,
body.dark-mode {
    background: var(--bg-body);
}

@media (prefers-color-scheme: dark) {
    body:not([data-theme="light"]) {
        background: var(--bg-body);
    }
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
}

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

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
    opacity: 0.2;
}

/* --- Surface (kept legacy class name `.glass-panel` to avoid touching all views) --- */
.glass-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

/* --- Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 20;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    border-right: 1px solid var(--border);
    padding: 20px 16px;
}

.sidebar,
.app-header {
    box-shadow: none;
    border-radius: 0;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    padding: 4px 0;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--color-brand), var(--color-brand-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 18px;
    font-family: 'Space Grotesk', sans-serif;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.sidebar-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-group-title,
.sidebar.collapsed .sidebar-user-info {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.sidebar.collapsed .theme-toggle-btn {
    display: none;
}

/* Nav */
.nav-group {
    margin-bottom: 24px;
}

.nav-group-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
    padding-left: 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.12);
    color: var(--color-brand);
    font-weight: 600;
}

[data-theme="dark"] .nav-item.active {
    background: rgba(129, 140, 248, 0.18);
    color: var(--color-brand-light);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .nav-item.active {
        background: rgba(129, 140, 248, 0.18);
        color: var(--color-brand-light);
    }
    html:not([data-theme="light"]) .nav-item.active::before {
        background: var(--color-brand-light);
    }
}

[data-theme="dark"] .nav-item.active::before {
    background: var(--color-brand-light);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    width: 3px;
    height: 24px;
    background: var(--color-brand);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px;
}

/* Sidebar toggle */
.sidebar-toggle {
    position: absolute;
    right: -14px;
    bottom: 96px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-brand);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: transform 0.3s ease;
    z-index: 21;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

/* Sidebar footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

.sidebar-user-link {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    border-radius: 10px;
    padding: 4px;
    margin: -4px;
    transition: background 0.15s ease;
}

.sidebar-user-link:hover {
    background: var(--bg-hover, rgba(127, 127, 127, 0.12));
}

.sidebar-logout {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-logout:hover {
    background: var(--bg-hover, rgba(239, 68, 68, 0.12));
    color: var(--color-danger);
}

.sidebar.collapsed .sidebar-logout {
    display: none;
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-brand), var(--color-brand-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-version {
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0.6;
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.sidebar-version .pulse-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Theme toggle button (next to logo) */
.theme-toggle-btn {
    margin-left: auto;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background: var(--bg-surface-elevated);
    color: var(--color-brand);
    border-color: var(--color-brand);
}

.theme-icon {
    width: 18px;
    height: 18px;
}

/* Show sun in dark mode, moon in light mode */
#themeIconSun { display: none; }
#themeIconMoon { display: block; }

[data-theme="dark"] #themeIconSun { display: block; }
[data-theme="dark"] #themeIconMoon { display: none; }

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) #themeIconSun { display: block; }
    html:not([data-theme="light"]) #themeIconMoon { display: none; }
}

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* Header */
.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 24px;
    font-weight: 600;
}

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

.search-input {
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    width: 240px;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Search field with magnifier icon */
.search-field {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.search-field .search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-field .search-input,
.search-field .form-control {
    padding-left: 36px;
}

/* Content area */
.content-area {
    padding: 32px;
}

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

.stat-card {
    border-radius: 16px;
    padding: 24px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.stat-card:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow-md);
}

/* Clickable stat cards (link to the filtered task list) */
a.stat-card {
    display: block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

a.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    font-size: 26px;
    margin-bottom: 12px;
}

.stat-card .stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 15px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* --- Analytics charts (dashboard) --- */
.chart-period-toggle {
    display: inline-flex;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}

.chart-period-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-period-btn:hover {
    color: var(--text-primary);
}

.chart-period-btn.active {
    background: var(--color-brand);
    color: #fff;
}

.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.analytics-summary-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.analytics-summary-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    color: var(--text-primary);
}

.analytics-summary-label {
    font-size: 13px;
    color: var(--text-muted);
}

.dashboard-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.chart-card {
    border-radius: 16px;
    padding: 24px;
}

.chart-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 20px;
}

.chart-body {
    height: 200px;
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 14px;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 100%;
}

.bar-col {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-width: 0;
}

.bar-track {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.bar {
    width: 70%;
    max-width: 28px;
    min-height: 2px;
    border-radius: 4px 4px 0 0;
    transition: height 0.3s ease, opacity 0.2s ease;
}

.bar-col:hover .bar {
    opacity: 0.8;
}

.bar-label {
    flex: 0 0 auto;
    margin-top: 6px;
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    text-align: center;
}

.bar-label-hidden {
    visibility: hidden;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 12px;
    border: none;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--color-brand);
    color: white;
}
.btn-primary:hover {
    background: var(--color-brand-dark);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-success {
    background: var(--color-success);
    color: white;
}
.btn-success:hover {
    opacity: 0.92;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}
.btn-danger:hover {
    opacity: 0.92;
    box-shadow: 0 2px 10px rgba(244, 63, 94, 0.35);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: rgba(99, 102, 241, 0.12);
    color: var(--color-brand);
    border-color: var(--color-brand);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 8px;
}

/* Action buttons in table rows: clear pointer + lift on hover */
.row-actions .btn {
    cursor: pointer;
}
.row-actions .btn:hover {
    transform: translateY(-1px) scale(1.08);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

/* --- Tables --- */
.table-container {
    border-radius: 24px;
    overflow: hidden;
}

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

thead th {
    padding: 14px 16px;
    text-align: left;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 14px 16px;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
}

tbody tr {
    transition: background 0.2s;
}

tbody tr:hover {
    background: var(--bg-surface-elevated);
}

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

/* --- Status Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-todo       { background: rgba(148, 163, 184, 0.15); color: var(--text-secondary); }
.badge-scheduled  { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.badge-running    { background: rgba(99, 102, 241, 0.15); color: #6366f1; }
.badge-done       { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-error      { background: rgba(244, 63, 94, 0.15); color: #f43f5e; }
.badge-stopped    { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.badge-timeout    { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }

.badge-running::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.5s infinite;
}

.badge-source {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    margin-left: 4px;
    vertical-align: middle;
}

.source-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.source-info a {
    color: var(--color-brand);
    text-decoration: none;
}

.source-info a:hover {
    text-decoration: underline;
}

.source-screenshot {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-top: 8px;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

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

select.form-control {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

select.form-control option,
select option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

.form-toggle {
    position: relative;
    width: 48px;
    height: 26px;
}

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

.form-toggle .toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--text-muted);
    border-radius: 13px;
    transition: 0.3s;
}

.form-toggle .toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

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

.form-toggle input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* --- Log Viewer --- */
.log-viewer {
    background: var(--log-bg);
    color: var(--log-text);
    border-radius: 16px;
    padding: 20px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-line-error {
    color: var(--log-error);
}

.log-line-success {
    color: var(--log-success);
}

.log-line-warning {
    color: var(--log-warning);
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 300px;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
}

.toast-success { background: var(--color-success); color: white; }
.toast-error   { background: var(--color-danger);  color: white; }
.toast-info    { background: var(--color-info);    color: white; }
.toast-warning { background: var(--color-warning); color: white; }

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

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

/* --- Modal --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: none;
}

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

.modal {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-md);
}

.modal-title {
    font-size: 18px;
    margin-bottom: 12px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* --- Spinner --- */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--color-brand);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* --- Utility --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.text-mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }

/* --- Documentation Tabs --- */
.doc-tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 8px;
}

.doc-tab {
    padding: 14px 24px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.doc-tab:hover {
    color: var(--text-primary);
    background: var(--bg-surface-elevated);
}

.doc-tab.active {
    color: var(--color-brand);
    border-bottom-color: var(--color-brand);
}

.doc-tab-pane {
    display: none;
}

.doc-tab-pane.active {
    display: block;
}

/* --- Steps list --- */
.step-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    margin-bottom: 8px;
    user-select: none;
}

.step-item:hover {
    background: var(--bg-surface-elevated);
    border-color: var(--text-muted);
}

.step-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--color-brand);
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.step-title {
    flex: 1;
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.45;
}

.step-item.is-done .step-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.step-delete {
    border: none;
    background: transparent;
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.step-item:hover .step-delete {
    opacity: 1;
}

.step-delete:hover {
    background: rgba(244, 63, 94, 0.12);
    color: var(--color-danger);
}

/* --- Resources tab (drop zone + grid) --- */
.resources-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    transition: all 0.2s ease;
    background: var(--bg-surface-elevated);
}

.resources-dropzone.dragover {
    border-color: var(--color-brand);
    background: rgba(99, 102, 241, 0.08);
}

.resources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

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

.resource-card img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    cursor: pointer;
    display: block;
}

.resource-card-name {
    padding: 6px 8px;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resource-card-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.resource-card:hover .resource-card-delete {
    opacity: 1;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-collapsed);
    }
    .sidebar .sidebar-title,
    .sidebar .nav-label,
    .sidebar .nav-group-title,
    .sidebar .sidebar-user-info,
    .sidebar .theme-toggle-btn {
        display: none;
    }
    .main-content {
        margin-left: var(--sidebar-collapsed);
    }
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    .content-area {
        padding: 16px;
    }
}

/* =========================================
   Run timeline (task detail)
   ========================================= */
.timeline-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 4px;
}

.timeline-item {
    border-left: 3px solid var(--border);
    padding: 8px 12px;
    border-radius: 0 8px 8px 0;
    background: var(--bg-surface);
    transition: background 0.15s;
}

.timeline-item:hover {
    background: var(--bg-surface-elevated);
}

.timeline-item.is-info    { border-left-color: var(--color-info); }
.timeline-item.is-success { border-left-color: var(--color-success); }
.timeline-item.is-error   { border-left-color: var(--color-danger); }

.timeline-head {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 13px;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.timeline-item.is-info    .timeline-dot { background: var(--color-info); }
.timeline-item.is-success .timeline-dot { background: var(--color-success); }
.timeline-item.is-error   .timeline-dot { background: var(--color-danger); }

.timeline-stage {
    font-family: 'Space Grotesk', monospace;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    letter-spacing: 0.3px;
}

.timeline-source {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--border);
    color: var(--text-secondary);
}

.timeline-ts {
    margin-left: auto;
    font-family: 'Space Grotesk', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.timeline-body {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    font-family: 'Space Grotesk', monospace;
}

.timeline-kv .k {
    color: var(--text-muted);
}
.timeline-kv .v {
    color: var(--text-primary);
    word-break: break-all;
}

/* --- Bulk actions (task list) --- */
.bulk-actions-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 12px;
}

.bulk-actions-bar[hidden] {
    display: none;
}

.bulk-actions-bar .bulk-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.bulk-actions-bar .bulk-count strong {
    color: var(--color-brand);
    font-weight: 600;
    margin-right: 2px;
}

.task-select-cell {
    width: 40px;
    text-align: center;
    padding: 0 8px;
}
.task-select-cell input[type="checkbox"] {
    cursor: pointer;
}

tr.task-row,
tr.project-row {
    cursor: pointer;
}
tr.task-row a,
tr.task-row button,
tr.task-row input,
tr.project-row a,
tr.project-row button,
tr.project-row input {
    cursor: auto;
}
tr.task-row input[type="checkbox"],
tr.project-row input[type="checkbox"] {
    cursor: pointer;
}
tr.task-row.selected td {
    background: rgba(99, 102, 241, 0.08);
}

/* --- Dashboard filters --- */
.dashboard-filters {
    padding: 16px 20px;
    margin-bottom: 16px;
}

.dashboard-filters .filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 16px;
    align-items: end;
}

.dashboard-filters .filter-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dashboard-filters .filter-field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.dashboard-filters .filter-field .form-control {
    padding: 8px 12px;
    font-size: 13px;
}

.dashboard-filters .filter-field-actions {
    align-self: end;
}

.dashboard-filters .filter-field-actions .btn {
    width: 100%;
}

/* --- Pagination bar --- */
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 4px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.pagination-bar[hidden] {
    display: none;
}

.pagination-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.pagination-info label {
    font-weight: 500;
}

.pagination-info .form-control-sm {
    width: auto;
    padding: 4px 8px;
    font-size: 0.875rem;
}

.pagination-range {
    margin-left: 4px;
    color: var(--text-secondary);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.pagination-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    background: var(--surface-2, transparent);
    color: var(--text-primary);
    border: 1px solid var(--border-color, rgba(127, 127, 127, 0.25));
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pagination-btn:hover:not(:disabled):not(.active) {
    background: rgba(99, 102, 241, 0.08);
    border-color: var(--color-brand);
}

.pagination-btn.active {
    background: var(--color-brand);
    color: #fff;
    border-color: var(--color-brand);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-ellipsis {
    padding: 0 6px;
    color: var(--text-secondary);
}

/* --- Resources / Documentation page --- */
.resources-page {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.resources-hero {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 28px 32px;
    border-radius: 16px;
}

.resources-hero-icon {
    font-size: 48px;
    line-height: 1;
}

.resources-hero-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 26px;
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-primary);
}

.resources-hero-subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
}

.resources-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    align-items: start;
}

.resources-toc {
    position: sticky;
    top: 24px;
    border-radius: 16px;
    padding: 20px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

.resources-toc-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.resources-toc nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.resources-toc-link {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.resources-toc-link:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.resources-toc-link.active {
    background: var(--bg-surface-elevated);
    color: var(--color-brand);
    border-left-color: var(--color-brand);
    font-weight: 600;
}

[data-theme="dark"] .resources-toc-link.active {
    color: var(--color-brand-light, #818cf8);
    border-left-color: var(--color-brand-light, #818cf8);
}

.resources-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.resources-section {
    border-radius: 16px;
    padding: 28px 32px;
    scroll-margin-top: 24px;
}

.resources-section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    user-select: none;
}

.resources-collapse-btn {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 20px;
    line-height: 1;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.resources-collapse-btn:hover {
    background: rgba(99, 102, 241, 0.12);
    color: var(--color-brand);
    border-color: var(--color-brand);
}

.resources-section.collapsed > .resources-section-title {
    margin-bottom: 0;
}

.resources-section.collapsed > *:not(.resources-section-title) {
    display: none;
}

.resources-subtitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 20px 0 10px;
}

.resources-section p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0 0 12px;
}

.resources-section code {
    background: var(--bg-surface-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--color-brand);
}

[data-theme="dark"] .resources-section code {
    color: var(--color-brand-light, #818cf8);
}

.resources-list {
    margin: 0 0 12px;
    padding-left: 22px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.resources-list li {
    margin-bottom: 4px;
}

.resources-list-badges {
    list-style: none;
    padding-left: 0;
}

.resources-list-badges li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.resources-code {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--text-primary);
    overflow-x: auto;
    white-space: pre;
    margin: 8px 0 16px;
    line-height: 1.6;
}

.resources-note {
    background: var(--bg-surface-elevated);
    border-left: 3px solid var(--color-warning, #f59e0b);
    padding: 10px 14px;
    border-radius: 0 8px 8px 0;
    font-size: 14px;
    color: var(--text-secondary);
    margin: 12px 0;
}

.resources-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 16px;
    font-size: 14px;
}

.resources-table thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid var(--border);
}

.resources-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: top;
}

.resources-table tbody tr:last-child td {
    border-bottom: none;
}

.resources-table code {
    white-space: nowrap;
}

@media (max-width: 1024px) {
    .resources-layout,
    .resources-api-layout {
        grid-template-columns: 1fr;
    }
    .resources-toc {
        position: static;
        max-height: none;
    }
}

/* === Resources — Tab navigation === */
.resources-tabs {
    display: flex;
    gap: 4px;
    padding: 8px;
    border-radius: 14px;
    flex-wrap: wrap;
}

.resources-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.resources-tab:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.resources-tab.active {
    background: var(--bg-surface-elevated);
    color: var(--color-brand);
    border-color: var(--color-brand);
    font-weight: 600;
}

[data-theme="dark"] .resources-tab.active {
    color: var(--color-brand-light, #818cf8);
    border-color: var(--color-brand-light, #818cf8);
}

.resources-tab-icon {
    font-size: 16px;
    line-height: 1;
}

/* === Resources — API tab === */
.resources-api-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    align-items: start;
}

.resources-api-endpoint {
    margin: 16px 0 20px;
    padding: 16px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.resources-api-endpoint:last-child {
    margin-bottom: 0;
}

.resources-api-endpoint-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.resources-api-method {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
    letter-spacing: 0.5px;
    color: #fff;
    min-width: 64px;
    text-align: center;
}

.resources-api-method-get    { background: #10b981; }
.resources-api-method-post   { background: #6366f1; }
.resources-api-method-put    { background: #f59e0b; }
.resources-api-method-delete { background: #ef4444; }

.resources-api-path {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: transparent !important;
    padding: 0 !important;
}

[data-theme="dark"] .resources-api-path {
    color: var(--text-primary);
}

.resources-api-description {
    margin: 8px 0 12px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.resources-api-endpoint .resources-code {
    margin: 0;
    font-size: 12.5px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* === Resources — Users tab === */
.resources-users-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.resources-users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 12px;
}

.resources-user-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-surface-elevated);
}

.resources-user-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-brand), var(--color-brand-light, #818cf8));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 700;
    flex-shrink: 0;
}

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

.resources-user-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.resources-user-name {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.resources-user-status {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.resources-user-status-active {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.resources-user-status-inactive {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-muted);
}

.resources-user-role {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.resources-user-email {
    font-size: 13px;
    margin-bottom: 10px;
}

.resources-user-email a {
    color: var(--color-brand);
    text-decoration: none;
}

[data-theme="dark"] .resources-user-email a {
    color: var(--color-brand-light, #818cf8);
}

.resources-user-email a:hover {
    text-decoration: underline;
}

.resources-user-context {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}
