/* ===================================================
   Sellabrew BrandFinder — Design System v2
   60:30:10 Rule  |  White · Sky Blue · Coral
   =================================================== */

/* ========== DESIGN TOKENS ========== */

/* --- Light Mode (Default) --- */
:root,
:root[data-theme="light"] {
    /* 60% — White Foundation */
    --white: #FFFFFF;
    --snow: #F7F9FC;
    --mist: #EEF2F7;

    /* 30% — Sky Blue */
    --sky: #00B4D8;
    --sky-dark: #0090B0;
    --sky-light: rgba(0, 180, 216, 0.06);
    --sky-glow: rgba(0, 180, 216, 0.12);

    /* 10% — Coral Red */
    --coral: #E8636F;
    --coral-dark: #D04E5A;
    --coral-light: rgba(232, 99, 111, 0.06);

    /* Neutrals */
    --ink: #1A202C;
    --slate: #4A5568;
    --ash: #A0AEC0;
    --sage: #38A169;
    --sage-light: rgba(56, 161, 105, 0.08);
    --amber: #D69E2E;
    --amber-light: rgba(214, 158, 46, 0.08);

    /* Semantic mapping */
    --bg-primary: var(--snow);
    --bg-secondary: var(--mist);
    --bg-card: var(--white);
    --bg-card-hover: var(--snow);
    --bg-glass: rgba(0, 180, 216, 0.02);
    --bg-input: var(--mist);
    --border: #E2E8F0;
    --border-focus: rgba(0, 180, 216, 0.4);
    --text-primary: var(--ink);
    --text-secondary: var(--slate);
    --text-muted: var(--ash);
    --accent: var(--sky);
    --accent-hover: var(--sky-dark);
    --accent-glow: var(--sky-light);
    --accent-light: var(--sky-light);
    --success: var(--sage);
    --success-bg: var(--sage-light);
    --danger: var(--coral);
    --danger-bg: var(--coral-light);
    --warning: var(--amber);
    --warning-bg: var(--amber-light);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08);

    /* Radius */
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 20px;
    --radius-pill: 999px;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-8: 48px;
    --space-10: 64px;
    --space-16: 96px;

    /* Typography */
    --font-heading: 'Outfit', 'Noto Sans JP', -apple-system, sans-serif;
    --font-body: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

/* --- Dark Mode --- */
:root[data-theme="dark"] {
    --white: #1A202C;
    --snow: #2D3748;
    --mist: #374151;
    --sky: #4DD0E1;
    --sky-dark: #80DEEA;
    --sky-light: rgba(77, 208, 225, 0.08);
    --sky-glow: rgba(77, 208, 225, 0.15);
    --coral: #FC8181;
    --coral-dark: #FEB2B2;
    --coral-light: rgba(252, 129, 129, 0.08);
    --ink: #F7FAFC;
    --slate: #CBD5E0;
    --ash: #718096;
    --sage: #68D391;
    --sage-light: rgba(104, 211, 145, 0.1);
    --amber: #F6E05E;
    --amber-light: rgba(246, 224, 94, 0.1);
    --bg-primary: var(--white);
    --bg-secondary: var(--snow);
    --bg-card: var(--snow);
    --bg-card-hover: var(--mist);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-input: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(77, 208, 225, 0.4);
    --text-primary: var(--ink);
    --text-secondary: var(--slate);
    --text-muted: var(--ash);
    --accent: var(--sky);
    --accent-hover: var(--sky-dark);
    --accent-glow: var(--sky-light);
    --accent-light: var(--sky-light);
    --success: var(--sage);
    --success-bg: var(--sage-light);
    --danger: var(--coral);
    --danger-bg: var(--coral-light);
    --warning: var(--amber);
    --warning-bg: var(--amber-light);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.3);
}


/* ========== RESET & BASE ========== */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--accent-hover);
}


/* ========== NAVIGATION ========== */

.nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: var(--space-5) var(--space-4);
    z-index: 100;
    transition: transform 0.3s ease;
}

.nav.hidden { display: none; }

.nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-2) var(--space-5);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-4);
}

.nav-logo { font-size: 22px; }

.nav-title {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.01em;
}

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

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-link:hover {
    background: var(--accent-glow);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon { font-size: 18px; }

.nav-logout {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.nav-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
}


/* ========== MAIN CONTENT ========== */

#page-content {
    margin-left: 0;
    padding: var(--space-6);
    min-height: 100vh;
    transition: margin-left 0.3s;
}

body.authenticated #page-content {
    margin-left: 240px;
}


/* ========== PAGE HEADER ========== */

.page-header {
    margin-bottom: var(--space-6);
}

.page-header h1 {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: var(--space-2);
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.page-header p {
    color: var(--text-secondary);
    font-size: 15px;
}


/* ========== CARDS ========== */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.card:hover {
    box-shadow: var(--shadow);
    border-color: var(--sky-glow);
}

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

.card-title {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}


/* ========== STAT CARDS ========== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-5);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--sky);
    opacity: 0;
    transition: opacity 0.2s;
}

.stat-card:hover::before { opacity: 1; }
.stat-card:hover { box-shadow: var(--shadow); }

.stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.stat-value.success { color: var(--success); }
.stat-value.danger { color: var(--danger); }
.stat-value.accent { color: var(--accent); }


/* ========== BUTTONS ========== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: var(--sky);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(0, 180, 216, 0.2);
}

.btn-primary:hover {
    background: var(--sky-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 180, 216, 0.25);
}

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

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

.btn-secondary:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid transparent;
}

.btn-danger:hover { border-color: var(--danger); }

.btn-success {
    background: var(--success);
    color: white;
}

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: var(--radius); }


/* ========== FORMS ========== */

.form-group { margin-bottom: var(--space-5); }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.form-input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--bg-card);
}

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


/* ========== SEARCH BOX ========== */

.search-container {
    position: relative;
    max-width: 600px;
}

.search-input {
    width: 100%;
    padding: 14px 20px 14px 48px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow), var(--shadow);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: var(--text-muted);
    pointer-events: none;
}


/* ========== TABLES ========== */

.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

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

th, td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--accent-light); }


/* ========== BADGES ========== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-neutral { background: var(--bg-input); color: var(--text-secondary); }


/* ========== PROGRESS BAR ========== */

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--sky);
    transition: width 0.5s ease;
}


/* ========== RATIO BAR ========== */

.ratio-bar { display: flex; align-items: center; gap: var(--space-2); }

.ratio-bar-track {
    flex: 1;
    height: 8px;
    background: var(--danger-bg);
    border-radius: 4px;
    overflow: hidden;
}

.ratio-bar-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.ratio-value {
    font-size: 13px;
    font-weight: 700;
    min-width: 45px;
    text-align: right;
}


/* ========== EMPTY STATE ========== */

.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-5);
    color: var(--text-muted);
}

.empty-state-icon { font-size: 48px; margin-bottom: var(--space-4); opacity: 0.4; }

.empty-state h3 {
    font-family: var(--font-heading);
    font-size: 18px;
    margin-bottom: var(--space-2);
    color: var(--text-secondary);
}

.empty-state p { font-size: 14px; margin-bottom: var(--space-5); }


/* ========== SPINNER ========== */

.spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg { width: 40px; height: 40px; border-width: 3px; }

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

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-10);
    gap: var(--space-4);
    color: var(--text-muted);
}


/* ========== LOGIN PAGE ========== */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-5);
    background: var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.login-header .logo { font-size: 48px; margin-bottom: var(--space-4); }

.login-header h1 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: var(--space-2);
    letter-spacing: -0.02em;
}

.login-header p { color: var(--text-secondary); font-size: 14px; }

.login-footer {
    text-align: center;
    margin-top: var(--space-5);
    font-size: 13px;
    color: var(--text-muted);
}

.login-footer a { color: var(--accent); font-weight: 600; }

.form-error {
    background: var(--danger-bg);
    color: var(--danger);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: var(--space-4);
    display: none;
}

.form-error.visible { display: block; }


/* ========== CONNECT CARDS (Settings) ========== */

.connect-card {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-5);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.connect-icon { font-size: 40px; }
.connect-info { flex: 1; }

.connect-info h3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: var(--space-1);
}

.connect-info p { color: var(--text-secondary); font-size: 13px; }

.connect-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}

.connect-status.connected { color: var(--success); }
.connect-status.disconnected { color: var(--text-muted); }


/* ========== FILTER BAR ========== */

.filter-bar {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}

.filter-btn {
    padding: 6px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.filter-btn:hover { border-color: var(--accent); color: var(--accent); }

.filter-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}


/* ========== PAGINATION ========== */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-5);
}

.pagination button {
    padding: var(--space-2) var(--space-4);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.pagination button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--text-muted); }


/* ========== TOASTS ========== */

.toast-container {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

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

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

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


/* ========== RESPONSIVE ========== */

@media (max-width: 768px) {
    .nav {
        transform: translateX(-100%);
        width: 100%;
        max-width: 280px;
    }

    .nav.open { transform: translateX(0); }
    body.authenticated #page-content { margin-left: 0; }
    #page-content { padding: var(--space-5); }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .page-header h1 { font-size: 22px; }
}


/* ========== CLICKABLE ROW ========== */

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-glow); }


/* ========== SEARCH STATUS WIDGET ========== */

.search-status-widget {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0;
    min-height: 80px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    margin-top: var(--space-3);
}

.ssw-container {
    border-top: 1px solid var(--border);
    padding-top: var(--space-3);
    margin-top: auto;
}

.ssw-header {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 var(--space-1) var(--space-2);
}

.ssw-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-1);
}

.ssw-job {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    margin-bottom: 6px;
    font-size: 12px;
    transition: border-color 0.3s;
}

.ssw-job:last-child { margin-bottom: 0; }

.ssw-job-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: var(--space-1);
}

.ssw-type {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-primary);
}

.ssw-query {
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ssw-running {
    border-color: var(--sky-glow);
    animation: ssw-pulse 2s ease-in-out infinite;
}

@keyframes ssw-pulse {
    0%, 100% { border-color: rgba(0, 180, 216, 0.1); }
    50% { border-color: rgba(0, 180, 216, 0.3); }
}

.ssw-progress {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-weight: 600;
    font-size: 11px;
}

.ssw-spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid var(--sky-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.ssw-completed { border-color: var(--sage-light); }
.ssw-failed { border-color: var(--coral-light); }

.ssw-result {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 11px;
    color: var(--text-secondary);
}

.ssw-check { font-size: 12px; }
.ssw-ago { margin-left: auto; color: var(--text-muted); font-size: 10px; }

.ssw-details {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    padding-left: 2px;
}


/* ========== THEME TOGGLE ========== */

.nav-theme-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-3);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: var(--space-2);
    flex-shrink: 0;
}

.nav-theme-toggle:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--accent-glow);
}

:root[data-theme="light"] .mode-btn {
    border: none !important;
}