/*
 * Codex Console - Apple Inspired Design System
 * Clean, Premium, Glassmorphism, SF Pro Typography
 * Support System Light/Dark Themes
 */

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

:root {
    /* System Colors - Light Mode (Apple Inspired) */
    --accent: #007AFF;
    --accent-hover: #0062CC;
    --accent-light: rgba(0, 122, 255, 0.1);
    
    --bg-system: #F5F5F7;
    --bg-secondary: #FFFFFF;
    --surface: rgba(255, 255, 255, 0.7);
    --surface-solid: #FFFFFF;
    --glass: rgba(255, 255, 255, 0.7);
    
    --text-primary: #1D1D1F;
    --text-secondary: #6E6E73;
    --text-muted: #86868B;
    
    --border: rgba(0, 0, 0, 0.1);
    --border-light: rgba(0, 0, 0, 0.05);
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.04);
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --radius-full: 99px;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Text", "Myriad Set Pro", "SF Pro Icons", "Apple Legacy Chevron", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
    --font-mono: "SF Mono", "SFMono-Regular", ui-monospace, "Menlo", "Consolas", monospace;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-system: #000000;
    --bg-secondary: #1C1C1E;
    --surface: rgba(28, 28, 30, 0.7);
    --surface-solid: #1C1C1E;
    --glass: rgba(28, 28, 30, 0.7);
    
    --text-primary: #F5F5F7;
    --text-secondary: #86868B;
    --text-muted: #6E6E73;
    
    --border: rgba(255, 255, 255, 0.1);
    --border-light: rgba(255, 255, 255, 0.05);
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.4);
    --shadow: 0 4px 12px rgba(0,0,0,0.6);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-system);
    color: var(--text-primary);
    line-height: 1.47;
    letter-spacing: -0.022em;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Glassmorphism Header */
.navbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
}

.nav-brand h1 {
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    gap: 32px;
}

.nav-link {
    text-decoration: none;
    font-size: 13px;
    color: var(--text-primary);
    opacity: 0.8;
    transition: var(--transition);
    font-weight: 400;
}

.nav-link:hover {
    opacity: 1;
}

.nav-link.active {
    font-weight: 600;
    opacity: 1;
}

/* Layout Parts */
.main-content {
    padding: 60px 0;
}

.page-header {
    margin-bottom: 40px;
}

.page-header h2 {
    font-size: 40px;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 19px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Premium Cards */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 24px;
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow);
}

.card-header {
    padding: 24px 32px 12px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.card-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.card-body {
    padding: 12px 32px 32px;
}

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

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

input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-system);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--text-primary);
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-secondary);
}

input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    accent-color: var(--accent);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #FFFFFF;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-system);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-ghost {
    background: transparent;
    color: var(--accent);
}

.btn-ghost:hover {
    background: var(--accent-light);
}

.btn-danger {
    background: #FF3B30;
    color: #FFFFFF;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 17px;
}

.btn-sm {
    padding: 4px 12px;
    font-size: 12px;
}

/* Console Log */
.console-log {
    background: #1C1C1E;
    color: #FFFFFF;
    padding: 24px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 13px;
    height: 400px;
    overflow-y: auto;
    line-height: 1.6;
}

.log-line { margin-bottom: 4px; border-radius: 4px; padding: 2px 8px; }
.log-line.info { color: #8E8E93; }
.log-line.success { color: #34C759; background: rgba(52, 199, 89, 0.1); }
.log-line.error { color: #FF3B30; background: rgba(255, 59, 48, 0.1); }
.log-line.warning { color: #FF9500; background: rgba(255, 149, 0, 0.1); }

/* Data Tables */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
}

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

.data-table th {
    text-align: left;
    padding: 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    background: var(--bg-system);
}

.data-table td {
    padding: 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-light);
}

.data-table tr:hover {
    background: var(--bg-system);
}

/* Badges */
.status-badge {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-badge.active, .status-badge.completed { background: #34C75922; color: #34C759; }
.status-badge.pending { background: #007AFF22; color: #007AFF; }
.status-badge.failed, .status-badge.error { background: #FF3B3022; color: #FF3B30; }

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

.stat-card {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--bg-secondary);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
    transform: scale(0.95);
    opacity: 0;
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: scale(1);
    opacity: 1;
}

/* Alert Modals (Confirmations) */
.modal-alert {
    max-width: 360px !important;
    text-align: center;
}

.modal-header {
    padding: 24px 24px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-alert .modal-header {
    justify-content: center;
    border-bottom: none;
    padding-bottom: 8px;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.modal-close-btn {
    background: var(--bg-system);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close-btn:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

/* Service Selection Grid (for Modals) */
.service-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.service-card {
    background: var(--bg-system);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.service-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    background: var(--surface-hover);
    box-shadow: 0 8px 16px rgba(0,0,0,0.05);
}

.service-card.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.service-card-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.service-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

.service-card-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    background: var(--accent);
    color: white;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s ease;
}

.service-card:hover .service-card-badge {
    opacity: 1;
    transform: scale(1);
}

/* Trigger styles for better UI instead of native select */
.select-trigger {
    background: var(--bg-system);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: var(--transition);
}

.select-trigger:hover {
    border-color: var(--border-hover);
    background: var(--bg-secondary);
}

.select-trigger-text {
    font-size: 14px;
    font-weight: 500;
}

.select-trigger-icon {
    font-size: 12px;
    color: var(--text-muted);
}

.modal-alert .modal-body {
    padding: 8px 32px 32px;
}

.modal-alert p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 24px;
}

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

.modal-alert .modal-actions {
    justify-content: center;
    margin-top: 0;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-item .label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item .value {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-all;
    display: flex;
    align-items: center;
    gap: 8px;
}

.token-box {
    background: var(--bg-system);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    position: relative;
    margin-top: 4px;
}

/* Custom Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 32px;
    padding: 4px;
    background: var(--bg-system);
    border-radius: 9px;
    width: fit-content;
}

.tab-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 7px;
    color: var(--text-secondary);
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn 0.4s ease-out; }

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    margin-left: 16px;
    opacity: 0.6;
}

.theme-toggle:hover { opacity: 1; }

/* Mobile */
@media (max-width: 768px) {
    .navbar { padding: 0 20px; }
    .nav-links { display: none; }
    .page-header h2 { font-size: 32px; }
}

/* Dropdowns */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    min-width: 180px;
    padding: 8px;
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.dropdown-menu.active, .dropdown.active .dropdown-menu {
    display: block !important;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
    transition: var(--transition);
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
}

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

.dropdown-item.danger {
    color: #FF3B30;
}

.dropdown-item.danger:hover {
    background: #FF3B3011;
}

/* Multi-select Dropdown (used in Index) */
.msd-dropdown {
    position: relative;
    width: 100%;
}

.msd-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-system);
    cursor: pointer;
}

/* Toast Notification System */
.toast-container {
    position: fixed;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 10px 24px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
    animation: slideInDown 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    min-width: 200px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.toast.success { border-left: 4px solid #34C759; }
.toast.error { border-left: 4px solid #FF3B30; }
.toast.warning { border-left: 4px solid #FF9500; }
.toast.info { border-left: 4px solid #007AFF; }

.toast-message {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    margin-left: auto;
    padding: 0 4px;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideOut {
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
}

.msd-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 100;
    display: none;
    max-height: 200px;
    overflow-y: auto;
    padding: 8px;
    box-shadow: var(--shadow-lg);
}

.msd-dropdown.open .msd-list {
    display: block;
}
/* Apple Style Switch */
.switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 44px;
}

.switch input {
    display: none;
}

.slider {
    background-color: #E9E9EA;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
}

.slider:before {
    background-color: #fff;
    bottom: 2px;
    content: "";
    height: 20px;
    left: 2px;
    position: absolute;
    transition: .4s;
    width: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

input:checked+.slider {
    background-color: #34C759;
}

input:checked+.slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}
