/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-bg-from: #e8eeff;
    --color-bg-to: #e0f2fe;
    --color-card-bg: #ffffff;
    --color-card-border: rgba(15, 23, 42, 0.08);
    --color-primary: #4f46e5;
    --color-primary-600: #4338ca;
    --color-primary-700: #3730a3;
    --color-outline: rgba(79, 70, 229, 0.35);
    --color-outline-weak: rgba(99, 102, 241, 0.2);
    --color-input-bg: #f8fafc;
    --color-input-border: #e2e8f0;
    --color-input-border-focus: #93c5fd;
    --color-error: #dc2626;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    line-height: 1.5;
    color: var(--color-text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Layout utilities */
.min-h-screen {
    min-height: 100vh;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.text-center {
    text-align: center;
}

.w-full {
    width: 100%;
}

.max-w-md {
    max-width: 28rem;
}

.mx-4 {
    margin-left: 1rem;
    margin-right: 1rem;
}

.mb-6 {
    margin-bottom: 1.5rem;
}

.p-4 {
    padding: 1rem;
}

/* Background gradients */
.bg-gradient { background: linear-gradient(135deg, var(--color-bg-from) 0%, var(--color-bg-to) 100%); }

/* Page management */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Card styles */
.card {
    background: var(--color-card-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 20px rgba(2, 6, 23, 0.06), 0 2px 6px rgba(2, 6, 23, 0.06);
    border: 1px solid var(--color-card-border);
    transition: transform 220ms ease, box-shadow 220ms ease;
}
.card:hover { transform: translateY(-1px); box-shadow: 0 16px 30px rgba(2, 6, 23, 0.12); }

.card-header { padding: 1.25rem 1.25rem 0; }

.card-content { padding: 1.25rem; }

.card-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 0.35rem; }

.card-description { color: var(--color-text-muted); font-size: 0.9rem; }

/* Table styles */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.table thead { background: #f8fafc; }

.table tbody tr:hover { background: #f4f7fb; }

.table-actions {
    display: flex;
    gap: 0.5rem;
}

/* Form styles */
.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
}

.input, .select {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
    background: var(--color-input-bg);
}
.input::placeholder { color: #94a3b8; }

.input:focus, .select:focus {
    outline: none;
    border-color: var(--color-input-border-focus);
    box-shadow: 0 0 0 4px var(--color-outline-weak);
    background: #ffffff;
}

/* Button styles */
.btn {
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 220ms ease, background 220ms ease, border-color 220ms ease, color 220ms ease;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}

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

.btn-primary {
    background: linear-gradient(180deg, var(--color-primary), var(--color-primary-600));
    color: #ffffff;
    border-color: var(--color-primary-600);
    box-shadow: 0 6px 14px rgba(79,70,229,0.25);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(180deg, var(--color-primary-600), var(--color-primary-700));
    border-color: var(--color-primary-700);
    transform: translateY(-1px);
}
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--color-outline); }

.btn-outline { background: transparent; color: #334155; border-color: #cbd5e1; }

.btn-outline:hover { background: #f1f5f9; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.btn-destructive { color: var(--color-error); border-color: var(--color-error); }

.btn-destructive:hover { background: #fef2f2; }

/* Tab styles */
.tabs-list { display: grid; grid-template-columns: 1fr 1fr; background: #eef2ff; border-radius: var(--radius-sm); padding: 0.3rem; margin-bottom: 1.2rem; border: 1px solid #e0e7ff; }

.tab-trigger { padding: 0.55rem 1rem; border: none; background: transparent; border-radius: 10px; font-weight: 600; cursor: pointer; transition: all 220ms ease; color: #475569; }

.tab-trigger.active { background: #ffffff; box-shadow: 0 4px 10px rgba(2,6,23,0.08); color: #111827; }

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Dashboard styles */
.container { max-width: 72rem; margin: 0 auto; padding: 1.25rem; }

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 2rem;
}

.header-content {
    flex: 1;
    min-width: 0;
}

.dashboard-title { font-size: 2rem; font-weight: 700; margin-bottom: 0.4rem; letter-spacing: -0.02em; word-break: break-word; }

.dashboard-subtitle { color: var(--color-text-muted); }

/* Location Selection Styles */
.location-selector {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.location-selector label {
    font-weight: 500;
    font-size: 0.875rem;
    color: #374151;
    margin-bottom: 0.75rem;
}

.location-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.location-card { padding: 1rem; border: 2px solid #e5e7eb; border-radius: 14px; background: #f8fafc; cursor: pointer; transition: all 220ms ease; position: relative; overflow: hidden; }

.location-card:hover { border-color: #cbd5e1; background: #f1f5f9; transform: translateY(-1px); box-shadow: 0 6px 16px rgba(2,6,23,0.08); }

.location-card.selected { border-color: #93c5fd; background: #eff6ff; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15); }

.location-card.selected::after {
    content: '✓';
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 1.5rem;
    height: 1.5rem;
    background: #3b82f6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

.location-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.location-flag { width: 2rem; height: 2rem; border-radius: 0.4rem; display: flex; align-items: center; justify-content: center; font-size: 1rem; background: #ffffff; border: 1px solid #e5e7eb; box-shadow: 0 2px 6px rgba(2,6,23,0.1); }

.location-name { font-weight: 700; color: #111827; font-size: 0.95rem; }

.location-description { color: #6b7280; font-size: 0.86rem; line-height: 1.5; }

.create-config-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.select-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.select-group label {
    font-weight: 500;
    font-size: 0.875rem;
}

/* Config list styles */
.configs-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.config-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 1rem; border: 1px solid #e5e7eb; border-radius: 12px; background: #f9fafb; transition: box-shadow 220ms ease, transform 220ms ease; }
.config-item:hover { box-shadow: 0 6px 16px rgba(2,6,23,0.08); transform: translateY(-1px); }

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

.config-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.config-name {
    font-weight: 500;
    word-break: break-word;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge { padding: 0.18rem 0.55rem; border-radius: 9999px; font-size: 0.72rem; font-weight: 600; background: #eef2ff; border: 1px solid #e0e7ff; color: #4f46e5; white-space: nowrap; }

.config-date { font-size: 0.88rem; color: var(--color-text-muted); }

.config-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Ensure header controls wrap nicely on small screens */
.header-controls { flex-wrap: wrap; }

/* Dashboard footer */
.dashboard-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0 2rem;
}
.dashboard-footer .footer-links,
.dashboard-footer .footer-actions { display:flex; gap: .5rem; flex-wrap: wrap; }

@media (max-width: 640px) {
    .dashboard-footer { flex-direction: column; align-items: stretch; }
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: #64748b;
}

/* Enhanced Toast Styles */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 24rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    min-width: 20rem;
    position: relative;
    animation: slideInRight 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.08);
    border: 1px solid;
    backdrop-filter: blur(8px);
}

.toast.removing {
    animation: slideOutRight 0.2s ease-in-out forwards;
}

.toast-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 600;
}

.toast-content {
    flex: 1;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    opacity: 0.7;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close:hover {
    opacity: 1;
}

.toast.success {
    background: rgba(240, 253, 244, 0.95);
    color: #166534;
    border-color: #bbf7d0;
}

.toast.success .toast-icon {
    background: #16a34a;
    color: white;
}

.toast.success .toast-close {
    color: #166534;
}

.toast.error {
    background: rgba(254, 242, 242, 0.95);
    color: #dc2626;
    border-color: #fecaca;
}

.toast.error .toast-icon {
    background: #dc2626;
    color: white;
}

.toast.error .toast-close {
    color: #dc2626;
}

.toast.info {
    background: rgba(239, 246, 255, 0.95);
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.toast.info .toast-icon {
    background: #3b82f6;
    color: white;
}

.toast.info .toast-close {
    color: #1d4ed8;
}

/* Toast Progress Bar */
.toast::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    border-radius: 0 0 0.75rem 0.75rem;
    opacity: 0.3;
    animation: progress 3s linear forwards;
}

@keyframes progress {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

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

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

/* Loading spinner */
.spinner {
    width: 2.2rem;
    height: 2.2rem;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile responsiveness */
@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }
    
    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .create-config-form {
        flex-direction: column;
        align-items: stretch;
    }
    
    .config-item {
        flex-direction: column;
        align-items: stretch;
    }
    
    .config-actions {
        justify-content: flex-start;
    }
    
    .dashboard-title {
        font-size: 1.5rem;
    }
    
    .card-header {
        padding: 1rem 1rem 0;
    }
    
    .card-content {
        padding: 1rem;
    }
    
    .location-grid {
        grid-template-columns: 1fr;
    }
    
    .toast-container {
        top: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
        max-width: none;
    }
    
    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .mx-4 {
        margin-left: 0.5rem;
        margin-right: 0.5rem;
    }
    
    .p-4 {
        padding: 0.5rem;
    }
    
    .location-card {
        padding: 0.75rem;
    }
    
    .location-flag {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.875rem;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .toast,
    .location-card,
    .btn,
    .input,
    .select {
        animation: none;
        transition: none;
    }
}

/* Focus styles for better accessibility */
.location-card:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.toast-close:focus {
    outline: 1px solid currentColor;
    outline-offset: 2px;
}

/* Subtle hover scaling for supported devices */
@media (hover: hover) {
    .btn:not(:disabled):hover { transform: translateY(-1px); }
}

/* Selection */
::selection { background: rgba(79, 70, 229, 0.2); color: #111827; }

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --color-text: #e5e7eb;
        --color-text-muted: #94a3b8;
        --color-bg-from: #0b1020;
        --color-bg-to: #0a182e;
        --color-card-bg: #0f172a;
        --color-card-border: rgba(148, 163, 184, 0.12);
        --color-input-bg: #0b1220;
        --color-input-border: #1f2a3a;
        --color-input-border-focus: #60a5fa;
        --color-outline: rgba(59, 130, 246, 0.35);
        --color-outline-weak: rgba(59, 130, 246, 0.22);
    }

    body { color: var(--color-text); }
    .card { background: var(--color-card-bg); }
    .card-title { color: #eef2ff; }
    .card-description { color: var(--color-text-muted); }
    .tabs-list { background: #121a2d; border-color: #1e293b; }
    .tab-trigger { color: #93a3bf; }
    .tab-trigger.active { color: #e2e8f0; background: #0b1220; }
    .table thead { background: #0b1220; }
    .table th, .table td { border-bottom-color: #1e293b; color: var(--color-text); }
    .table tbody tr:hover { background: #0b1220; }
    .input, .select { background: var(--color-input-bg); color: var(--color-text); }
    .btn-outline { color: #cbd5e1; border-color: #334155; }
    .btn-outline:hover { background: #121a2d; }
    .location-card { background: #0b1220; border-color: #1e293b; }
    .location-card:hover { background: #0d1526; border-color: #334155; }
    .location-card.selected { background: #0d1526; box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.18); }
    .location-flag { background: #0f172a; border-color: #1e293b; }
    .location-name { color: #e5e7eb; }
    .location-description { color: #94a3b8; }
    .config-item { background: #0b1220; border-color: #1e293b; }
    .badge { background: rgba(79, 70, 229, 0.15); border: 1px solid rgba(99, 102, 241, 0.25); color: #c7d2fe; }
    .toast.success { background: rgba(6, 78, 59, 0.2); color: #34d399; border-color: rgba(34, 197, 94, 0.3); }
    .toast.error { background: rgba(127, 29, 29, 0.2); color: #f87171; border-color: rgba(248, 113, 113, 0.3); }
    .toast.info { background: rgba(30, 58, 138, 0.2); color: #93c5fd; border-color: rgba(147, 197, 253, 0.3); }
}

/* Explicit theme control via data-theme="light|dark" on <html> */
html[data-theme="light"] {
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-bg-from: #e8eeff;
    --color-bg-to: #e0f2fe;
    --color-card-bg: #ffffff;
    --color-card-border: rgba(15, 23, 42, 0.08);
    --color-primary: #4f46e5;
    --color-primary-600: #4338ca;
    --color-primary-700: #3730a3;
    --color-outline: rgba(79, 70, 229, 0.35);
    --color-outline-weak: rgba(99, 102, 241, 0.2);
    --color-input-bg: #f8fafc;
    --color-input-border: #e2e8f0;
    --color-input-border-focus: #93c5fd;
    --color-error: #dc2626;
}

html[data-theme="dark"] {
    --color-text: #e5e7eb;
    --color-text-muted: #94a3b8;
    --color-bg-from: #0b1020;
    --color-bg-to: #0a182e;
    --color-card-bg: #0f172a;
    --color-card-border: rgba(148, 163, 184, 0.12);
    --color-input-bg: #0b1220;
    --color-input-border: #1f2a3a;
    --color-input-border-focus: #60a5fa;
    --color-outline: rgba(59, 130, 246, 0.35);
    --color-outline-weak: rgba(59, 130, 246, 0.22);
}

/* Component overrides when theme is forced explicitly */
html[data-theme="dark"] body { color: var(--color-text); }
html[data-theme="dark"] .card { background: var(--color-card-bg); }
html[data-theme="dark"] .card-title { color: #eef2ff; }
html[data-theme="dark"] .card-description { color: var(--color-text-muted); }
html[data-theme="dark"] .tabs-list { background: #121a2d; border-color: #1e293b; }
html[data-theme="dark"] .tab-trigger { color: #93a3bf; }
html[data-theme="dark"] .tab-trigger.active { color: #e2e8f0; background: #0b1220; }
html[data-theme="dark"] .table thead { background: #0b1220; }
html[data-theme="dark"] .table th, 
html[data-theme="dark"] .table td { border-bottom-color: #1e293b; color: var(--color-text); }
html[data-theme="dark"] .table tbody tr:hover { background: #0b1220; }
html[data-theme="dark"] .input, 
html[data-theme="dark"] .select { background: var(--color-input-bg); color: var(--color-text); }
html[data-theme="dark"] .btn-outline { color: #cbd5e1; border-color: #334155; }
html[data-theme="dark"] .btn-outline:hover { background: #121a2d; }
html[data-theme="dark"] .btn-primary { background: linear-gradient(180deg, #6366f1, #4f46e5); border-color: #4f46e5; box-shadow: 0 6px 14px rgba(99,102,241,0.25); }
html[data-theme="dark"] .location-card { background: #0b1220; border-color: #1e293b; }
html[data-theme="dark"] .location-card:hover { background: #0d1526; border-color: #334155; }
html[data-theme="dark"] .location-card.selected { background: #0d1526; box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.18); }
html[data-theme="dark"] .location-flag { background: #0f172a; border-color: #1e293b; }
html[data-theme="dark"] .location-name { color: #e5e7eb; }
html[data-theme="dark"] .location-description { color: #94a3b8; }
html[data-theme="dark"] .config-item { background: #0b1220; border-color: #1e293b; }
html[data-theme="dark"] .badge { background: rgba(79, 70, 229, 0.15); border: 1px solid rgba(99, 102, 241, 0.25); color: #c7d2fe; }
html[data-theme="dark"] .toast.success { background: rgba(6, 78, 59, 0.2); color: #34d399; border-color: rgba(34, 197, 94, 0.3); }
html[data-theme="dark"] .toast.error { background: rgba(127, 29, 29, 0.2); color: #f87171; border-color: rgba(248, 113, 113, 0.3); }
html[data-theme="dark"] .toast.info { background: rgba(30, 58, 138, 0.2); color: #93c5fd; border-color: rgba(147, 197, 253, 0.3); }

html[data-theme="light"] body { color: var(--color-text); }
html[data-theme="light"] .card { background: var(--color-card-bg); }
html[data-theme="light"] .card-title { color: #111827; }
html[data-theme="light"] .card-description { color: var(--color-text-muted); }
html[data-theme="light"] .tabs-list { background: #eef2ff; border-color: #e0e7ff; }
html[data-theme="light"] .tab-trigger { color: #475569; }
html[data-theme="light"] .tab-trigger.active { color: #111827; background: #ffffff; }
html[data-theme="light"] .table thead { background: #f8fafc; }
html[data-theme="light"] .table th, 
html[data-theme="light"] .table td { border-bottom-color: #e5e7eb; color: var(--color-text); }
html[data-theme="light"] .table tbody tr:hover { background: #f4f7fb; }
html[data-theme="light"] .input, 
html[data-theme="light"] .select { background: var(--color-input-bg); color: var(--color-text); }
html[data-theme="light"] .btn-outline { color: #334155; border-color: #cbd5e1; }
html[data-theme="light"] .btn-outline:hover { background: #f1f5f9; }
html[data-theme="light"] .btn-primary { background: #000000; border-color: #000000; color: #ffffff; box-shadow: 0 6px 14px rgba(0,0,0,0.25); }
html[data-theme="light"] .btn-primary:hover { background: #111111; border-color: #111111; }
html[data-theme="light"] .location-card { background: #f8fafc; border-color: #e5e7eb; }
html[data-theme="light"] .location-card:hover { background: #f1f5f9; border-color: #cbd5e1; }
html[data-theme="light"] .location-card.selected { background: #eff6ff; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15); }
html[data-theme="light"] .location-flag { background: #ffffff; border-color: #e5e7eb; }
html[data-theme="light"] .location-name { color: #111827; }
html[data-theme="light"] .location-description { color: #6b7280; }
html[data-theme="light"] .config-item { background: #f9fafb; border-color: #e5e7eb; }
html[data-theme="light"] .badge { background: #eef2ff; border: 1px solid #e0e7ff; color: #000000; }
html[data-theme="light"] .toast.success { background: rgba(240, 253, 244, 0.95); color: #166534; border-color: #bbf7d0; }
html[data-theme="light"] .toast.error { background: rgba(254, 242, 242, 0.95); color: #dc2626; border-color: #fecaca; }
html[data-theme="light"] .toast.info { background: rgba(239, 246, 255, 0.95); color: #1d4ed8; border-color: #bfdbfe; }
