:root {
    --bg: #0d0d0d;
    --surface: #1c1c1e;
    --surface2: #2c2c2e;
    --accent: #0a84ff;
    --accent2: #30d158;
    --danger: #ff453a;
    --warning: #ff9f0a;
    --text: #ffffff;
    --text2: #ffffff;
    --text3: #ffffff;
    --border: #38383a;
    --tab-h: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: dark;
}

html.light-theme {
    --bg: #ffffff;
    --surface: #f2f2f7;
    --surface2: #e5e5ea;
    --text: #000000;
    --text2: #000000;
    --text3: #000000;
    --border: #c6c6c8;
    color-scheme: light;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    background: var(--bg);
    color: var(--text);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

/* Header */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

#header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}

/* Content */
#content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

/* Bottom Tab Nav */
#tabs {
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: calc(var(--tab-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text3);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 6px 0;
    transition: color 0.2s;
}

.tab.active { color: var(--accent); }
.tab:hover { color: var(--text2); }

/* Flash messages — bottom toast */
.flash {
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.35);
    animation: flash-slidein 0.3s ease;
    transition: opacity 0.3s, transform 0.3s;
}

@keyframes flash-slidein {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.flash-close {
    background: none;
    border: none;
    color: inherit;
    opacity: 0.75;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}
.flash-close:hover { opacity: 1; }

.flash-success { background: #248a3d; color: #ffffff; }
.flash-error   { background: #c0392b; color: #ffffff; }
.flash-warning { background: #c47a00; color: #ffffff; }

/* Cards */
.card {
    background: var(--surface);
    border-radius: 12px;
    margin-bottom: 2px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    cursor: pointer;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    flex: 1;
}

.card-meta {
    font-size: 0.85rem;
    color: var(--text2);
    margin-left: 12px;
    white-space: nowrap;
}

.card-chevron {
    color: var(--text3);
    margin-left: 8px;
    transition: transform 0.2s;
    font-size: 0.9rem;
}

.card.expanded .card-chevron { transform: rotate(90deg); }
.card.expanded { border: 1px solid var(--border); }

.card-body {
    display: none;
    padding: 0 14px 14px;
}

.card.expanded .card-body { display: block; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    text-decoration: none;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); width: 100%; }
.btn-success { background: var(--accent2); width: 100%; }
.btn-danger { background: var(--danger); }
.btn-surface { background: #48484a; }
.btn-back { background: #6E4AC7; white-space: nowrap; margin-bottom: 16px; }

.btn-sm {
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
.btn-row > * { flex: 1; }
.btn-row > .btn-back { flex: 0; min-width: 80px; margin-bottom: 0; }

/* Forms */
.field-group {
    background: var(--surface);
    border-radius: 14px;
    margin-bottom: 16px;
    overflow: hidden;
}

.field-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text);
    letter-spacing: 0.8px;
    padding: 16px 14px 8px;
}

/* Collapsible form panes */
.collapsible-pane {
    margin-bottom: 16px;
}
.collapsible-pane > summary {
    background: var(--surface);
    border-radius: 14px;
    padding: 10px 14px;
    cursor: pointer;
    list-style: none;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text);
    letter-spacing: 0.8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}
.collapsible-pane > summary::-webkit-details-marker { display: none; }
.collapsible-pane > summary::after {
    content: '›';
    font-size: 1.1rem;
    color: var(--text3);
    display: inline-block;
    transform: rotate(90deg);
    transition: transform 0.2s;
}
details[open].collapsible-pane > summary {
    border-radius: 14px 14px 0 0;
}
details[open].collapsible-pane > summary::after {
    transform: rotate(270deg);
}
.collapsible-pane > .field-group {
    border-radius: 0 0 14px 14px;
    margin-bottom: 0;
}

.field-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.field-row:last-child { border-bottom: none; }

.field-row label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.field-row input,
.field-row select,
.field-row textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    padding: 4px 0;
}

.field-row input::placeholder,
.field-row textarea::placeholder {
    color: var(--text3);
}

.field-row select {
    appearance: auto;
    -webkit-appearance: menulist;
}

.field-row select option {
    background: var(--surface);
    color: var(--text);
}

.field-row textarea {
    min-height: 60px;
    resize: vertical;
}

.field-row input[type="date"],
.field-row input[type="time"] { width: auto; flex: 0; }

.field-row input[type="checkbox"] { flex: 0; width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.field-row .badge { align-self: flex-start; }

/* Checkbox rows */
.check-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.check-row:last-child { border-bottom: none; }

.check-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.check-row label {
    font-size: 0.9rem;
    cursor: pointer;
    flex: 1;
}

.check-row .check-meta {
    font-size: 0.75rem;
    color: var(--text3);
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-active { background: var(--accent2); color: #ffffff; }
.badge-inactive { background: var(--danger); color: #ffffff; }
.badge-role { background: var(--accent); color: #ffffff; }

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--warning);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Section header */
.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text);
    letter-spacing: 0.8px;
    margin: 20px 0 10px;
    padding-left: 14px;
}

/* Login page */
.login-container {
    max-width: 360px;
    margin: 60px auto;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 24px;
}

/* Login form fields — stacked label-above-input layout */
.login-fields {
    background: var(--surface);
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 16px;
}

.login-field {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.login-field:last-child { border-bottom: none; }

.login-field label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.login-field input {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 1rem;
    padding: 2px 0;
}

/* App toggle cards */
.app-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app-card-info { flex: 1; }
.app-card-name { font-size: 0.95rem; font-weight: 600; }
.app-card-desc { font-size: 0.8rem; color: var(--text3); margin-top: 2px; }

/* Tab bar — retired, never shown */
#tabs { display: none; }

/* Theme toggle icon button */
#themeToggleBtn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 2px;
    user-select: none;
}

/* Hamburger — always visible */
#app { position: relative; }

.nav-hamburger {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.nav-hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
}

/* Password show/hide toggle */
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text3);
    padding: 0;
    display: flex;
    align-items: center;
}

.nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 56px;
    right: 0;
    width: max-content;
    min-width: 160px;
    background: var(--surface);
    padding: 0.25rem 0 0.75rem;
    z-index: 1000;
    gap: 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    list-style: none;
    border-radius: 0 0 0 10px;
}

.nav-links.open { display: flex; }

.nav-links li {
    border-top: 1px solid var(--border);
}

.nav-links a {
    display: block;
    padding: 0.75rem 1.75rem;
    font-size: 0.9rem;
    color: var(--text);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    white-space: nowrap;
}

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

/* Admin table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th {
    text-align: left;
    padding: 10px 8px;
    color: var(--text);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.admin-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text2);
}

.admin-table tr:last-child td { border-bottom: none; }

/* Spinner */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}

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

@media (max-width: 768px) {
    #content {
        height: auto;
        padding-bottom: 16px;
    }
}
