:root {
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #eff6ff;
    --header-bg: #0f172a;
    --header-text: #f8fafc;
    --header-muted: #94a3b8;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.08);
    --app-width: 1080px;
    --app-padding: 1.25rem;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface-muted);
    line-height: 1.5;
}

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: var(--app-width);
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-lg);
}

.app-topbar {
    background: var(--header-bg);
    color: var(--header-text);
    border-bottom: 1px solid #1e293b;
}

.app-topbar-inner,
.app-nav-inner,
.context-strip-inner,
.app-main {
    width: 100%;
    margin: 0;
    padding-left: var(--app-padding);
    padding-right: var(--app-padding);
}

.app-topbar-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 3.25rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.app-brand {
    color: var(--header-text);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.app-brand span {
    color: var(--header-muted);
    font-weight: 500;
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.app-topbar-spacer { flex: 1; }

.workspace-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.workspace-picker label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--header-muted);
    white-space: nowrap;
}

.workspace-picker select {
    width: auto;
    min-width: 11rem;
    max-width: 16rem;
    padding: 0.4rem 2rem 0.4rem 0.65rem;
    font-size: 0.875rem;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #1e293b url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E") no-repeat right 0.6rem center;
    color: var(--header-text);
    appearance: none;
}

.workspace-picker select:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--header-muted);
    white-space: nowrap;
}

.user-menu strong { color: var(--header-text); font-weight: 600; }

.user-menu a {
    color: #cbd5e1;
    text-decoration: none;
}

.user-menu a:hover { color: #fff; }

.app-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.app-nav-inner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    overflow: visible;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 0.85rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-muted);
}

.nav-link.is-active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.nav-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--border);
    margin: 0 0.35rem;
    align-self: center;
}

.nav-admin { margin-left: auto; }

.context-strip {
    background: var(--primary-soft);
    border-bottom: 1px solid #bfdbfe;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

.context-strip-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #1e3a8a;
}

.context-strip a { color: #1d4ed8; font-weight: 500; }

.app-main {
    flex: 1;
    padding-top: 1.75rem;
    padding-bottom: 3rem;
}

.page-header { margin-bottom: 1.5rem; }

.page-header h1 {
    margin: 0 0 0.35rem;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.page-lead {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.muted { color: var(--text-muted); font-size: 0.9rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.35rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.card-title {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    background: var(--primary);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    font-family: inherit;
}

.btn:hover { background: var(--primary-hover); color: #fff; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-sm { padding: 0.38rem 0.8rem; font-size: 0.82rem; }

.btn.is-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    text-align: left;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    background: var(--surface-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-critical { background: #fef2f2; color: #991b1b; }
.badge-high { background: #fff7ed; color: #c2410c; }
.badge-medium { background: #fefce8; color: #a16207; }
.badge-low { background: #f0fdf4; color: #166534; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.score { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.score-good { color: #166534; }
.score-mid { color: #a16207; }
.score-bad { color: #991b1b; }

input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--surface);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid #93c5fd;
    outline-offset: 0;
    border-color: #93c5fd;
}

textarea { min-height: 80px; resize: vertical; }

label.field-label,
.field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.chip-list li {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.82rem;
}

.field-compare {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
}

.field-compare-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.field-compare-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.value-lines { margin: 0; padding-left: 1.1rem; }
.value-lines li { margin-bottom: 0.2rem; }

.text-block {
    white-space: pre-wrap;
    line-height: 1.45;
    max-height: 10rem;
    overflow: auto;
    background: var(--surface-muted);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.88rem;
    border: 1px solid var(--border);
}

.section-title {
    margin: 2rem 0 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.filter-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.filter-panel .filter-context {
    flex: 1;
    min-width: 12rem;
}

.filter-panel .filter-context-value {
    font-weight: 600;
    font-size: 0.95rem;
}

.filter-panel .filter-context-value a {
    text-decoration: none;
}

.filter-panel .filter-context-value a:hover {
    text-decoration: underline;
}

.search-input {
    width: min(300px, 100%);
}

.empty-hint {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-style: italic;
}

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge-ok { background: #f0fdf4; color: #166534; }
.status-badge-edited { background: #eff6ff; color: #1d4ed8; }
.status-badge-pending { background: #fffbeb; color: #a16207; }
.status-badge-na { background: #f3f4f6; color: #6b7280; }

.workflow-steps {
    margin: 0;
    padding-left: 1.25rem;
}

.workflow-steps li { margin-bottom: 0.35rem; }

.compare-note {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #92400e;
}

@media (max-width: 768px) {
    .grid-2, .field-compare-cols { grid-template-columns: 1fr; }
    .app-topbar-inner { flex-wrap: wrap; }
    .workspace-picker { width: 100%; }
    .workspace-picker select { flex: 1; max-width: none; }
    .nav-admin { margin-left: 0; }
}
