/* ============================================
   Modern Theme System with Light/Dark Modes
   Light: Burnt Peach, Pearl Beige, Blue Slate, Pale Sky, Alabaster Grey
   Dark: Black, Dark Khaki, Stone Brown, Lavender Grey, Sky Reflection
   ============================================ */

/* Light Theme */
:root {
    /* Background Colors */
    --bg-primary: #eaeaea;        /* Alabaster Grey */
    --bg-secondary: #e8dab2;      /* Pearl Beige */
    --bg-card: #c0d6df;           /* Pale Sky */
    --bg-elevated: #c0d6df;
    --bg-hover: #d5e4ea;
    --bg-input: #ffffff;

    /* Text Colors */
    --text-primary: #36311f;      /* Dark Khaki - for contrast */
    --text-secondary: #4f6d7a;    /* Blue Slate */
    --text-muted: #6b8a96;
    --text-inverse: #ffffff;

    /* Brand Colors - Blue Slate as primary */
    --primary: #4f6d7a;           /* Blue Slate */
    --primary-light: #6b8a96;
    --primary-dark: #3d5560;
    --primary-bg: rgba(79, 109, 122, 0.15);

    /* Accent Colors - Burnt Peach */
    --accent: #dd6e42;            /* Burnt Peach */
    --accent-light: #e58b66;
    --accent-dark: #c45a32;
    --accent-bg: rgba(221, 110, 66, 0.15);

    /* Semantic Colors */
    --success: #4a9c6d;
    --success-light: #6bb88a;
    --success-bg: rgba(74, 156, 109, 0.15);

    --warning: #d4a03a;
    --warning-light: #e0b85a;
    --warning-bg: rgba(212, 160, 58, 0.15);

    --error: #c75050;
    --error-light: #d87070;
    --error-bg: rgba(199, 80, 80, 0.15);

    --info: #4f6d7a;              /* Blue Slate */
    --info-light: #6b8a96;
    --info-bg: rgba(79, 109, 122, 0.15);

    /* Border & Shadow */
    --border: #b8c9d0;
    --border-focus: var(--primary);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.12), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Sidebar specific */
    --sidebar-bg: linear-gradient(180deg, #4f6d7a 0%, #3d5560 100%);
    --sidebar-text: #eaeaea;
    --sidebar-text-muted: #c0d6df;
    --sidebar-border: rgba(255, 255, 255, 0.15);
    --sidebar-hover: rgba(255, 255, 255, 0.1);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    --gradient-accent: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    --gradient-card: linear-gradient(145deg, var(--bg-card) 0%, #d5e4ea 100%);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Border Radius */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
}

/* Dark Theme */
[data-theme="dark"] {
    /* Background Colors */
    --bg-primary: #020300;        /* Black */
    --bg-secondary: #36311f;      /* Dark Khaki */
    --bg-card: #36311f;           /* Dark Khaki */
    --bg-elevated: #59544b;       /* Stone Brown */
    --bg-hover: #59544b;          /* Stone Brown */
    --bg-input: #36311f;

    /* Text Colors */
    --text-primary: #eaeaea;      /* Light text for dark bg */
    --text-secondary: #c0d6df;    /* Pale Sky */
    --text-muted: #7d8ca3;        /* Lavender Grey */
    --text-inverse: #020300;

    /* Brand Colors - Sky Reflection as primary */
    --primary: #79a9d1;           /* Sky Reflection */
    --primary-light: #9bc0de;
    --primary-dark: #5a8fbd;
    --primary-bg: rgba(121, 169, 209, 0.2);

    /* Accent Colors - lighter version of Burnt Peach */
    --accent: #e58b66;
    --accent-light: #eba88a;
    --accent-dark: #dd6e42;
    --accent-bg: rgba(229, 139, 102, 0.2);

    /* Semantic Colors - Brighter for dark mode */
    --success: #6bb88a;
    --success-light: #8dcea6;
    --success-bg: rgba(107, 184, 138, 0.2);

    --warning: #e0b85a;
    --warning-light: #e8c97a;
    --warning-bg: rgba(224, 184, 90, 0.2);

    --error: #d87070;
    --error-light: #e29090;
    --error-bg: rgba(216, 112, 112, 0.2);

    --info: #79a9d1;              /* Sky Reflection */
    --info-light: #9bc0de;
    --info-bg: rgba(121, 169, 209, 0.2);

    /* Border & Shadow */
    --border: #59544b;            /* Stone Brown */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.4);

    /* Sidebar specific */
    --sidebar-bg: linear-gradient(180deg, #020300 0%, #36311f 100%);
    --sidebar-text: #eaeaea;
    --sidebar-text-muted: #7d8ca3;
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --sidebar-hover: rgba(255, 255, 255, 0.08);

    /* Gradients */
    --gradient-card: linear-gradient(145deg, #36311f 0%, #020300 100%);
}

/* ============================================
   Base Styles
   ============================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 15px;
    transition: background var(--transition-normal), color var(--transition-normal);
}

/* ============================================
   Layout
   ============================================ */

.layout {
    display: flex;
    min-height: 100vh;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    padding: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.brand {
    padding: 24px 20px;
    font-size: 1.25em;
    font-weight: 700;
    color: var(--primary-light);
    border-bottom: 1px solid var(--sidebar-border);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: var(--radius-full);
    box-shadow: 0 0 12px var(--primary);
}

.brand-selector {
    padding: 16px 20px;
    border-bottom: 1px solid var(--sidebar-border);
}

.brand-selector label {
    display: block;
    margin-bottom: 8px;
    color: var(--sidebar-text-muted);
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.brand-selector select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text);
    font-size: 0.9em;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.brand-selector select:hover {
    background: rgba(255, 255, 255, 0.08);
}

.brand-selector select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.brand-selector select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.nav-menu {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.95em;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    margin: 2px 0;
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: var(--primary-light);
    border-left-color: var(--primary);
}

.nav-link.active {
    background: var(--primary-bg);
    color: var(--primary-light);
    border-left-color: var(--primary);
}

/* Collapsible Nav Group */
.nav-group {
    list-style: none;
}

.nav-group-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-chevron {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 0.85em;
}

.nav-chevron.open {
    transform: rotate(90deg);
}

.nav-group-items {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.nav-group-items.open {
    max-height: 200px;
}

.nav-group-items .nav-link {
    padding-left: 36px;
    font-size: 0.9em;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logout-link {
    color: var(--sidebar-text-muted) !important;
    font-size: 0.9em;
}

.logout-link:hover {
    color: var(--accent) !important;
}

/* Theme Toggle Button */
.theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius);
    padding: 8px 10px;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 1.1em;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--primary-light);
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
    flex: 1;
    padding: 32px 40px;
    margin-left: 240px;
    min-height: 100vh;
    background: var(--bg-primary);
}

.select-brand-prompt {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}

.select-brand-prompt h2 {
    color: var(--text-primary);
    margin-bottom: 12px;
    font-weight: 600;
}

/* ============================================
   Typography
   ============================================ */

h1 {
    font-size: 1.875em;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

h2 {
    font-size: 1.375em;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

h3 {
    font-size: 1.125em;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

/* ============================================
   Cards
   ============================================ */

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all var(--transition-normal);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
}

/* Dashboard card specific styles */
.card.actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card.actions .btn {
    width: 100%;
}

.card.brand-info h3 {
    color: var(--primary);
    margin-bottom: 16px;
}

.card.brand-info p {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.card.domain-counts h3,
.card.recent-operations h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* ============================================
   Domain Counts
   ============================================ */

.count-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    text-align: center;
}

.count-item {
    padding: 5px;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    transition: all var(--transition-fast);
}

.count-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.count-item .count {
    display: block;
    font-size: 2.25em;
    font-weight: 700;
    line-height: 1.2;
}

.count-item .label {
    font-size: 0.85em;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.count-item.active .count { color: var(--success); }
.count-item.ready .count { color: var(--info); }
.count-item.unset .count { color: var(--warning); }
.count-item.blocked .count { color: var(--error); }

/* ============================================
   Buttons
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--gradient-accent);
    color: white;
    box-shadow: 0 2px 8px rgba(225, 29, 72, 0.3);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(225, 29, 72, 0.4);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #047857 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, var(--error) 0%, #B91C1C 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8em;
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
}

/* ============================================
   Tables
   ============================================ */

.data-table, .operations-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

.data-table th,
.data-table td,
.operations-table th,
.operations-table td {
    padding: 14px 16px;
    text-align: left;
}

.data-table th,
.operations-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.data-table td,
.operations-table td {
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.data-table tr:last-child td,
.operations-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td,
.operations-table tbody tr:hover td {
    background: var(--bg-hover);
}

.clickable-row {
    cursor: pointer;
}

/* ============================================
   Status Colors
   ============================================ */

.status-success, .status-active, .status-completed {
    color: var(--success);
}

.status-running, .status-pending, .status-ready, .status-in_progress {
    color: var(--warning);
}

.status-failed, .status-blocked, .status-error {
    color: var(--error);
}

.status-unset, .status-skipped {
    color: var(--text-muted);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.status-success,
.status-badge.status-completed {
    background: var(--success-bg);
    color: var(--success);
}

.status-badge.status-failed,
.status-badge.status-error {
    background: var(--error-bg);
    color: var(--error);
}

.status-badge.status-running,
.status-badge.status-pending,
.status-badge.status-in_progress {
    background: var(--warning-bg);
    color: var(--warning);
}

/* ============================================
   Messages & Alerts
   ============================================ */

.action-message, .success-message, .error-message, .warning-message, .info-message {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin: 16px 0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.action-message.success, .success-message, .success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success);
}

.action-message.error, .error-message, .error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error);
}

.action-message.warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.warning-message {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.info-message {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid var(--info);
}

/* ============================================
   Forms
   ============================================ */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9em;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95em;
    transition: all var(--transition-fast);
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: var(--text-muted);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

/* Checkbox styling */
.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    accent-color: var(--primary);
}

/* ============================================
   Login Page
   ============================================ */

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-primary);
    padding: 20px;
}

.login-box {
    background: var(--bg-card);
    padding: 48px 40px;
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.login-box h2 {
    text-align: center;
    margin-bottom: 32px;
    color: var(--primary);
    font-size: 1.5em;
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px var(--primary-bg);
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-bg);
}

/* ============================================
   Operation Detail
   ============================================ */

.operation-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.operation-id {
    font-size: 1.25em;
    font-weight: 700;
    color: var(--text-primary);
}

.operation-info {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius-lg);
    margin-bottom: 28px;
    border: 1px solid var(--border);
}

.info-row {
    display: flex;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row .label {
    width: 160px;
    color: var(--text-secondary);
    font-weight: 500;
}

.info-row .value {
    flex: 1;
    color: var(--text-primary);
}

.error-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Toolbar
   ============================================ */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 24px;
    padding: 16px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

/* ============================================
   Empty State
   ============================================ */

.no-data {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1.1em;
}

/* ============================================
   Scrollbar Styling (for webkit browsers)
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

.animate-pulse {
    animation: pulse 2s infinite;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
        padding: 24px;
    }
}

@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }

    .main-content {
        margin-left: 0;
        padding: 20px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .count-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
