/* Kelly - Apple-Inspired Design System */
/* Based on DESIGN.md: SF Pro, binary sections, single blue accent */

@font-face {
    font-family: 'SF Pro Display';
    src: local('SF Pro Display'), local('.SFNSDisplay-Regular'), local('-apple-system');
    font-weight: 100 900;
    font-display: swap;
}

@font-face {
    font-family: 'SF Pro Text';
    src: local('SF Pro Text'), local('.SFNSText-Regular'), local('-apple-system');
    font-weight: 100 900;
    font-display: swap;
}

:root {
    /* Apple Core Colors */
    --apple-blue: #0071e3;
    --apple-blue-hover: #0077ED;
    --link-blue: #0066cc;
    --link-blue-dark: #2997ff;

    /* Surfaces */
    --bg-black: #000000;
    --bg-light: #f5f5f7;
    --bg-white: #ffffff;

    /* Text */
    --text-primary: #1d1d1f;
    --text-secondary: rgba(0, 0, 0, 0.8);
    --text-tertiary: rgba(0, 0, 0, 0.56);
    --text-muted: rgba(0, 0, 0, 0.48);

    /* Dark surfaces */
    --dark-surface-1: #161617;
    --dark-surface-2: #1d1d1f;
    --dark-surface-3: #2a2a2d;
    --dark-surface-4: #323236;

    /* Functional */
    --success: #34C759;
    --warning: #FF9500;
    --danger: #FF3B30;
    --info: #5856D6;

    /* Borders */
    --border-color: rgba(0, 0, 0, 0.06);
    --border-color-subtle: rgba(0, 0, 0, 0.04);

    /* Shadows */
    --shadow-card: rgba(0, 0, 0, 0.04) 0px 1px 3px, rgba(0, 0, 0, 0.04) 0px 4px 12px;
    --shadow-elevated: rgba(0, 0, 0, 0.08) 0px 4px 16px, rgba(0, 0, 0, 0.04) 0px 8px 32px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 64px;

    /* Radius */
    --radius-sm: 5px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-pill: 980px;

    /* Typography */
    --font-display: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-text: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.25, 0.1, 0.25, 1);

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 48px;
    --content-max: 980px;
}

/* Dark mode */
[data-theme="dark"] {
    --bg-light: #000000;
    --bg-white: #161617;
    --text-primary: #f5f5f7;
    --text-secondary: rgba(255, 255, 255, 0.8);
    --text-tertiary: rgba(255, 255, 255, 0.56);
    --text-muted: rgba(255, 255, 255, 0.48);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-subtle: rgba(255, 255, 255, 0.04);
    --shadow-card: rgba(0, 0, 0, 0.2) 0px 1px 3px, rgba(0, 0, 0, 0.15) 0px 4px 12px;
    --shadow-elevated: rgba(0, 0, 0, 0.3) 0px 4px 16px, rgba(0, 0, 0, 0.2) 0px 8px 32px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-text);
    font-size: 17px;
    line-height: 1.47;
    letter-spacing: -0.374px;
    color: var(--text-primary);
    background: var(--bg-light);
    min-height: 100vh;
}

a {
    color: var(--link-blue);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    text-decoration: underline;
}

[data-theme="dark"] a {
    color: var(--link-blue-dark);
}

/* Typography */
.headline-hero {
    font-family: var(--font-display);
    font-size: 56px;
    font-weight: 600;
    line-height: 1.07;
    letter-spacing: -0.28px;
}

.headline-section {
    font-family: var(--font-display);
    font-size: 40px;
    font-weight: 600;
    line-height: 1.10;
    letter-spacing: -0.4px;
}

.headline-tile {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 400;
    line-height: 1.14;
    letter-spacing: 0.196px;
}

.headline-card {
    font-family: var(--font-display);
    font-size: 21px;
    font-weight: 700;
    line-height: 1.19;
    letter-spacing: 0.231px;
}

.text-body {
    font-family: var(--font-text);
    font-size: 17px;
    font-weight: 400;
    line-height: 1.47;
    letter-spacing: -0.374px;
}

.text-caption {
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.29;
    letter-spacing: -0.224px;
}

.text-micro {
    font-family: var(--font-text);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.33;
    letter-spacing: -0.12px;
}

/* Cards */
.apple-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

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

.apple-card-static {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
}

[data-theme="dark"] .apple-card,
[data-theme="dark"] .apple-card-static {
    background: var(--dark-surface-1);
}

/* Legacy class support */
.glass-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-card);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

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

.glass-card-static {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-card);
}

[data-theme="dark"] .glass-card,
[data-theme="dark"] .glass-card-static {
    background: var(--dark-surface-1);
    box-shadow: var(--shadow-card);
}

/* Buttons */
.apple-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 8px 15px;
    font-family: var(--font-text);
    font-size: 17px;
    font-weight: 400;
    line-height: 1;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.apple-button:hover {
    text-decoration: none;
}

.apple-button:active {
    transform: scale(0.97);
}

.apple-button.primary {
    background: var(--apple-blue);
    color: #ffffff;
}

.apple-button.primary:hover {
    background: var(--apple-blue-hover);
    color: #ffffff;
}

.apple-button.dark {
    background: var(--dark-surface-2);
    color: #ffffff;
}

.apple-button.dark:hover {
    background: var(--dark-surface-3);
    color: #ffffff;
}

.apple-button.pill {
    border-radius: var(--radius-pill);
    border: 1px solid var(--link-blue);
    background: transparent;
    color: var(--link-blue);
    font-size: 14px;
    padding: 8px 18px;
}

.apple-button.pill:hover {
    background: var(--apple-blue);
    color: #ffffff;
    border-color: var(--apple-blue);
}

[data-theme="dark"] .apple-button.pill {
    border-color: var(--link-blue-dark);
    color: var(--link-blue-dark);
}

/* Legacy button classes */
.glass-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 8px 18px;
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.43;
    letter-spacing: -0.224px;
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.glass-button:hover {
    text-decoration: none;
}

.glass-button:active {
    transform: scale(0.97);
}

.glass-button.primary {
    background: var(--apple-blue);
    color: #ffffff;
}

.glass-button.primary:hover {
    background: var(--apple-blue-hover);
    color: #ffffff;
}

.glass-button.secondary {
    background: transparent;
    color: var(--link-blue);
    border: 1px solid var(--link-blue);
}

.glass-button.secondary:hover {
    background: var(--apple-blue);
    color: #ffffff;
    border-color: var(--apple-blue);
}

[data-theme="dark"] .glass-button.secondary {
    color: var(--link-blue-dark);
    border-color: var(--link-blue-dark);
}

.glass-button.success {
    background: var(--success);
    color: #ffffff;
}

.glass-button.danger {
    background: var(--danger);
    color: #ffffff;
}

.glass-button.sm {
    padding: 6px 14px;
    font-size: 12px;
}

.glass-button.lg {
    padding: 12px 24px;
    font-size: 17px;
}

.glass-button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    transform: none;
}

/* Inputs */
.glass-input {
    width: 100%;
    padding: 11px 16px;
    font-family: var(--font-text);
    font-size: 17px;
    line-height: 1.47;
    letter-spacing: -0.374px;
    color: var(--text-primary);
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.glass-input:focus {
    border-color: var(--apple-blue);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.glass-input::placeholder {
    color: var(--text-muted);
}

[data-theme="dark"] .glass-input {
    background: var(--dark-surface-1);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

[data-theme="dark"] .glass-input:focus {
    border-color: var(--link-blue-dark);
    box-shadow: 0 0 0 3px rgba(41, 151, 255, 0.2);
}

textarea.glass-input {
    resize: vertical;
    min-height: 100px;
}

select.glass-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23636366' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* Forms */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.29;
    letter-spacing: -0.224px;
    color: var(--text-secondary);
}

.form-group small {
    display: block;
    margin-top: var(--space-xs);
    font-size: 12px;
    letter-spacing: -0.12px;
    color: var(--text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

/* Badge */
.glass-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-family: var(--font-text);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.33;
    letter-spacing: -0.12px;
    border-radius: var(--radius-pill);
}

.glass-badge.info { background: rgba(88, 86, 214, 0.1); color: var(--info); }
.glass-badge.success { background: rgba(52, 199, 89, 0.1); color: var(--success); }
.glass-badge.warning { background: rgba(255, 149, 0, 0.1); color: var(--warning); }
.glass-badge.danger { background: rgba(255, 59, 48, 0.1); color: var(--danger); }
.glass-badge.primary { background: rgba(0, 113, 227, 0.1); color: var(--apple-blue); }

/* Table */
.glass-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-text);
    font-size: 14px;
    letter-spacing: -0.224px;
}

.glass-table thead {
    border-bottom: 1px solid var(--border-color);
}

.glass-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.glass-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.glass-table tbody tr {
    transition: background var(--transition-fast);
}

.glass-table tbody tr:hover {
    background: rgba(0, 113, 227, 0.03);
}

[data-theme="dark"] .glass-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Toggle Switch */
.glass-toggle {
    position: relative;
    width: 51px;
    height: 31px;
    appearance: none;
    background: var(--dark-surface-4);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--transition-base);
    border: none;
    outline: none;
}

.glass-toggle::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform var(--transition-base);
}

.glass-toggle:checked {
    background: var(--success);
}

.glass-toggle:checked::before {
    transform: translateX(20px);
}

/* Sidebar Navigation */
.glass-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    padding: var(--space-lg) var(--space-md);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

[data-theme="dark"] .glass-sidebar {
    background: rgba(0, 0, 0, 0.85);
}

.sidebar-logo {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.14;
    letter-spacing: -0.28px;
    color: #ffffff;
    padding: 0 var(--space-md);
    margin-bottom: var(--space-2xl);
}

.sidebar-nav {
    list-style: none;
    flex: 1;
}

.sidebar-nav li {
    margin-bottom: 2px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 9px var(--space-md);
    color: rgba(255, 255, 255, 0.72);
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    letter-spacing: -0.224px;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    text-decoration: none;
}

.sidebar-nav a:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.sidebar-nav a.active {
    color: #ffffff;
    background: rgba(0, 113, 227, 0.4);
    font-weight: 600;
}

.sidebar-nav .nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.8;
    flex-shrink: 0;
}

.sidebar-nav a.active .nav-icon,
.sidebar-nav a:hover .nav-icon {
    opacity: 1;
}

.sidebar-user {
    padding: var(--space-md);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--apple-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 13px;
}

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

.sidebar-user-name {
    font-weight: 600;
    font-size: 13px;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.56);
    text-transform: capitalize;
}

.sidebar-user a {
    color: rgba(255, 255, 255, 0.56);
    transition: color var(--transition-fast);
}

.sidebar-user a:hover {
    color: #ffffff;
    text-decoration: none;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: var(--space-xl) var(--space-2xl);
}

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2xl);
}

.content-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.14;
    letter-spacing: 0.196px;
    color: var(--text-primary);
}

.content-subtitle {
    font-family: var(--font-text);
    font-size: 14px;
    line-height: 1.43;
    letter-spacing: -0.224px;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-lg);
}

.dashboard-grid-wide {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-lg);
}

/* KPI Card */
.kpi-card {
    padding: var(--space-xl);
}

.kpi-label {
    font-family: var(--font-text);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 40px;
    font-weight: 600;
    line-height: 1.10;
    letter-spacing: -0.4px;
    color: var(--text-primary);
}

.kpi-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: var(--space-sm);
    font-family: var(--font-text);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: -0.12px;
}

.kpi-change.up { color: var(--success); }
.kpi-change.down { color: var(--danger); }
.kpi-change.stable { color: var(--text-muted); }

/* Alerts */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    letter-spacing: -0.224px;
    margin-bottom: var(--space-lg);
    line-height: 1.43;
}

.alert-success {
    background: rgba(52, 199, 89, 0.08);
    color: var(--success);
}

.alert-error {
    background: rgba(255, 59, 48, 0.08);
    color: var(--danger);
}

.alert-warning {
    background: rgba(255, 149, 0, 0.08);
    color: var(--warning);
}

.alert-info {
    background: rgba(88, 86, 214, 0.08);
    color: var(--info);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    box-shadow: var(--shadow-elevated);
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    letter-spacing: -0.224px;
    animation: slideInRight 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
    max-width: 360px;
}

[data-theme="dark"] .toast {
    background: var(--dark-surface-3);
}

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

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-elevated);
    padding: var(--space-2xl);
    max-width: 560px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

[data-theme="dark"] .modal-content {
    background: var(--dark-surface-2);
}

/* Progress Bar */
.glass-progress {
    height: 4px;
    background: var(--border-color);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.glass-progress-bar {
    height: 100%;
    background: var(--apple-blue);
    border-radius: var(--radius-pill);
    transition: width var(--transition-slow);
}

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-white) 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* File Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-3xl);
    text-align: center;
    transition: all var(--transition-base);
    cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--apple-blue);
    background: rgba(0, 113, 227, 0.03);
}

.upload-zone-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.4;
}

.upload-zone-text {
    color: var(--text-tertiary);
    font-size: 14px;
    letter-spacing: -0.224px;
}

/* Responsive */
@media (max-width: 768px) {
    .glass-sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-base);
    }

    .glass-sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: var(--space-md);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid-wide {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .content-title {
        font-size: 21px;
    }

    .kpi-value {
        font-size: 28px;
    }
}

@media (max-width: 1024px) {
    .dashboard-grid-wide {
        grid-template-columns: 1fr;
    }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 14px; letter-spacing: -0.224px; }
.text-xs { font-size: 12px; letter-spacing: -0.12px; }
.text-lg { font-size: 21px; letter-spacing: 0.231px; }
.font-bold { font-weight: 700; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.hidden { display: none; }
