:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252833;
    --border: #2d3142;
    --text: #e4e6eb;
    --text-muted: #8b8fa3;
    --primary: #4caf50;
    --primary-hover: #66bb6a;
    --danger: #ef5350;
    --warning: #ffa726;
    --success: #66bb6a;
    --sidebar-w: 240px;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Login */
.login-card {
    max-width: 380px;
    margin: 15vh auto;
    padding: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.login-card h1 { text-align: center; margin-bottom: 0.25rem; font-size: 1.75rem; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.5rem; }

.login-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-card input {
    padding: 0.65rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}
.login-card input:focus { outline: none; border-color: var(--primary); }

.signup-toggle { margin-top: 1rem; color: var(--text-muted); }
.signup-toggle summary { cursor: pointer; font-size: 0.85rem; }
.signup-toggle form { margin-top: 0.75rem; }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }
.success { color: var(--success); font-size: 0.85rem; margin-top: 0.5rem; }

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); color: #fff; }

/* Layout */
#main-view {
    display: flex;
    min-height: 100vh;
}

#sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
}

.nav-brand { padding: 1.25rem 1rem; border-bottom: 1px solid var(--border); }
.nav-brand h2 { font-size: 1.15rem; }

#nav-links {
    list-style: none;
    padding: 0.5rem 0;
    flex: 1;
}
#nav-links li a {
    display: block;
    padding: 0.6rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}
#nav-links li a:hover { color: var(--text); background: var(--bg-input); }
#nav-links li a.active { color: var(--primary); background: rgba(76, 175, 80, 0.1); border-right: 3px solid var(--primary); }

.nav-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}
#user-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

#content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 2rem;
}

.page h1 { margin-bottom: 1rem; font-size: 1.5rem; }

.surface-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.surface-card h3 {
    margin-bottom: 0.85rem;
}

/* Toast */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.85rem;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: #42a5f5; }
.toast-warning { background: var(--warning); color: #000; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}
th, td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
th { color: var(--text-muted); font-weight: 600; }
tbody tr:hover { background: var(--bg-input); }

/* Responsive — moved to bottom of file */

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.toolbar input, .toolbar select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
}

textarea {
    width: 100%;
    min-height: 120px;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.stack-field {
    display: block;
    margin: 0.75rem 0;
}

.stack-field span {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.compliance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}

/* Inline forms */
.inline-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: end;
    margin: 0.75rem 0;
}
.inline-form input, .inline-form select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    min-width: 120px;
}
.inline-form input:focus { outline: none; border-color: var(--primary); }

/* Dashboard cards */
.dash-cards {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.dash-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    text-align: center;
    min-width: 160px;
}
.dash-card h3 { font-size: 2rem; color: var(--primary); margin-bottom: 0.25rem; }
.dash-card p { color: var(--text-muted); font-size: 0.85rem; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-pass { background: rgba(76,175,80,0.2); color: var(--success); }
.badge-fail { background: rgba(239,83,80,0.2); color: var(--danger); }
.badge-pending { background: rgba(255,167,38,0.2); color: var(--warning); }

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1rem;
}
.tab-bar button, .qc-tab {
    padding: 0.6rem 1.25rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.tab-bar button.active, .qc-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Result box */
.result-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
}
.result-box:empty { display: none; }

/* Details/summary */
details {
    margin: 0.75rem 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}
details summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
}
details[open] summary { margin-bottom: 0.75rem; }

/* Loading spinner */
.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 1rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Button loading state */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Dashboard accent cards */
.dash-card-accent h3 { color: #42a5f5 !important; }
.dash-card-warn h3 { color: var(--warning) !important; }
.dash-card-danger h3 { color: var(--danger) !important; }

/* Admin grid */
.admin-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
@media (min-width: 1024px) {
    .admin-grid {
        grid-template-columns: 1fr 1fr;
    }
    .admin-grid > :first-child {
        grid-column: 1 / -1;
    }
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0;
}
.stat-item {
    text-align: center;
    padding: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius);
}
.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Confirmation modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
}
.modal-card h3 { margin-bottom: 0.75rem; }
.modal-card .modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* Scrollable table wrapper */
.table-wrap {
    overflow-x: auto;
    margin: 1rem 0;
}

/* Hint text */
.hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Pre code blocks in result boxes */
.result-box pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text);
}

/* Mobile nav toggle */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    #main-view { flex-direction: column; }
    #content { margin-left: 0; padding: 1rem; }
    .dash-cards { flex-direction: column; }
    .dash-card { min-width: auto; }
    .compliance-grid { grid-template-columns: 1fr; }
    .admin-grid { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form input, .inline-form select { min-width: auto; }
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Smooth transitions */
.page { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Sustainability & Trends */
.sust-panel { margin-top: 1rem; }
.badge-danger { background: rgba(239,83,80,0.2); color: var(--danger); }
.badge-low { background: rgba(76,175,80,0.2); color: var(--success); }
.badge-medium { background: rgba(255,167,38,0.2); color: var(--warning); }
.badge-high { background: rgba(239,83,80,0.2); color: var(--danger); }
.truncate { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Comment thread */
.comment-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
.comment-item p { margin: 0.25rem 0 0; }
.comment-item .hint { font-size: 0.75rem; color: var(--text-muted); }

/* Eco score chip */
.eco-chip {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Tab bar for sustainability tabs */
.sust-tab {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    margin-right: 2px;
}
.sust-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Btn danger */
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c62828; }

/* Select styling */
select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}
select:focus { outline: none; border-color: var(--primary); }
