:root {
    --bg: #f6f8fb;
    --card: #ffffff;
    --line: #d8dee8;
    --text: #1c2430;
    --muted: #667387;
    --primary: #1947a3;
    --primary-hover: #143a84;
    --secondary: #eef3fb;
    --danger: #c0392b;
    --success: #1f7a4d;
    --warning: #a96f00;
    --shadow: 0 8px 20px rgba(20, 35, 60, 0.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    width: min(1400px, calc(100% - 2rem));
    margin: 0 auto;
}

.site-header {
    background: linear-gradient(135deg, #12284f, #1a3f78);
    color: #fff;
    padding: 1rem 0;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.brand {
    color: #fff;
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle { font-size: 0.9rem; opacity: 0.9; }
.user-meta { text-align: right; font-size: 0.95rem; }

.site-nav {
    background: #0f1f3b;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.nav-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
    padding: 0.5rem 0;
}

.site-nav a {
    color: #dfe8fb;
    padding: 0.55rem 0.8rem;
    border-radius: 8px;
}

.site-nav a:hover {
    background: rgba(255,255,255,0.08);
    text-decoration: none;
}

.nav-spacer { flex: 1 1 auto; }
.page-body { padding: 1.25rem 0 2rem; }

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

.page-header-tight { margin-bottom: 1.5rem; }
.page-header h1 { margin: 0 0 0.25rem; font-size: 1.8rem; }
.muted { color: var(--muted); }
.link-back { display: inline-block; margin-top: 0.3rem; }

.card,
.metric-card,
.narrow-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.card,
.narrow-card { padding: 1rem 1.1rem; }
.narrow-card { max-width: 760px; margin: 0 auto; }
.metric-card { padding: 1rem; }
.metric-card.danger { border-left: 5px solid var(--danger); }
.metric-label { color: var(--muted); font-size: 0.9rem; }
.metric-value { font-size: 2rem; font-weight: 700; margin-top: 0.35rem; }
.metric-value.small { font-size: 1.2rem; }

.card-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-auto-fit { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.section-header h2,
.card h2,
.narrow-card h1 { margin-top: 0; }

.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}

.quick-link {
    display: block;
    padding: 0.8rem 0.9rem;
    border-radius: 12px;
    background: var(--secondary);
    border: 1px solid var(--line);
    font-weight: 600;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.table th,
.table td {
    padding: 0.7rem 0.6rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.table th { background: #f9fbfe; font-weight: 700; }
.table .sub-row td { background: #fcfdff; color: var(--muted); }
.compact-table th,
.compact-table td { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.actions-cell { white-space: nowrap; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.62rem 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn-small { padding: 0.35rem 0.6rem; font-size: 0.84rem; }
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary {
    background: var(--secondary);
    color: var(--text);
    border-color: var(--line);
}
.btn-secondary:hover { text-decoration: none; background: #e8eef9; }

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

.filter-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filter-grid-3 {
    grid-template-columns: 1fr 260px auto;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.72rem 0.78rem;
    border: 1px solid #c7d2e2;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(25, 71, 163, 0.18);
    border-color: var(--primary);
}

.checkbox,
input[type="checkbox"] {
    width: auto;
    transform: scale(1.1);
}

.file-input { padding: 0.4rem; }
.stack-form { display: grid; gap: 1rem; }
.field-block { display: grid; gap: 0.35rem; }
.field-block label { font-weight: 600; }
.help-text { font-size: 0.88rem; color: var(--muted); }
.field-error { font-size: 0.9rem; color: var(--danger); }
.has-error input,
.has-error select,
.has-error textarea { border-color: var(--danger); }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.detail-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
}
.detail-list div {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 0.75rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px dashed var(--line);
}
.detail-list dt { font-weight: 700; }
.detail-list dd { margin: 0; }

.messages { display: grid; gap: 0.75rem; margin-bottom: 1rem; }
.message,
.error-box {
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
}
.message.success { border-color: #b9e1c8; background: #edf9f1; }
.message.warning { border-color: #e7d19b; background: #fff6df; }
.message.error,
.error-box { border-color: #efb8b2; background: #fff0ef; }

.simple-list { margin: 0; padding-left: 1.1rem; }
.pagination {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    justify-content: flex-end;
    margin-top: 1rem;
}
.json-box {
    margin: 0;
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
}

@media (max-width: 1100px) {
    .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .grid-2,
    .filter-grid-3,
    .filter-bar { grid-template-columns: 1fr; }
    .header-inner,
    .page-header,
    .section-header { flex-direction: column; align-items: flex-start; }
    .detail-list div { grid-template-columns: 1fr; }
    .table { display: block; overflow-x: auto; }
}

.nav-logout-form {
    display: inline;
    margin: 0;
}

.nav-logout-button {
    background: transparent;
    border: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
    padding: 0;
}
