:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-border: #dde1e6;
    --color-text: #1f2430;
    --color-muted: #6b7280;
    --color-accent: #1d4ed8;
    --color-accent-hover: #1e40af;
    --color-top: #fff7e6;
    --color-top-border: #f2b93b;
    --radius: 8px;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; max-width: 100%; }

body {
    font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    overflow-x: hidden;
    max-width: 100%;
}

.page {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

header.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 8px;
}

header.site-header .brand {
    font-weight: 700;
    font-size: 1.05rem;
}

header.site-header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}

header.site-header nav a {
    color: var(--color-muted);
    text-decoration: none;
    font-size: 0.92rem;
    white-space: nowrap;
}

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

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
p.subtitle { color: var(--color-muted); margin: 0 0 24px; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

label {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    margin: 14px 0 6px;
}
label:first-child { margin-top: 0; }

input[type=text], input[type=date], input[type=password], input[type=url], select, textarea {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
    box-sizing: border-box;
}

/* iOS Safari gives the native date control its own intrinsic sizing that
   can ignore the width above unless -webkit-appearance is reset. */
input[type=date] {
    -webkit-appearance: none;
    appearance: none;
}

.quill-editor {
    background: #fff;
    border-radius: 0 0 6px 6px;
}

.quill-editor .ql-editor {
    min-height: 260px;
    font-size: 0.95rem;
}

.ql-toolbar { border-radius: 6px 6px 0 0; }

button, .btn {
    display: inline-block;
    background: var(--color-accent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
button:hover, .btn:hover { background: var(--color-accent-hover); }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: #eef0f3; }

.btn-danger { background: #b91c1c; }
.btn-danger:hover { background: #991b1b; }

.actions { margin-top: 18px; display: flex; gap: 10px; }

.flash-success {
    background: #ecfdf3;
    border: 1px solid #86efac;
    color: #166534;
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 18px;
}
.flash-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #991b1b;
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 18px;
}

.date-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.date-bar input[type=date] { width: auto; }

.date-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.date-list a {
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    text-decoration: none;
}
.date-list a.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }

.sector-block { margin-bottom: 24px; }
.sector-title {
    font-weight: 700;
    font-size: 1.02rem;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--color-border);
}

.entry {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
}
.entry.is-top { background: var(--color-top); border-color: var(--color-top-border); }

.entry-meta-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.entry-institution { font-weight: 700; font-size: 0.85rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .02em; }
.entry-category {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    background: #eef2ff;
    color: var(--color-accent);
}
.entry-submitted {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    background: #f0f1f3;
    color: var(--color-muted);
    margin-left: auto;
    white-space: nowrap;
}
.entry-headline { font-weight: 700; font-size: 1.05rem; margin: 4px 0 8px; }
.entry-excerpt { font-size: 0.94rem; color: var(--color-muted); margin: 0; }
.entry-body { font-size: 0.94rem; margin-top: 8px; }
.entry-body ul, .entry-body ol { margin: 6px 0; padding-left: 22px; }

.entry-details { margin-top: 6px; }
.entry-details summary {
    cursor: pointer;
    color: var(--color-accent);
    font-size: 0.88rem;
    font-weight: 600;
    list-style: none;
}
.entry-details summary::-webkit-details-marker { display: none; }
.entry-details summary::after { content: " →"; }
.entry-details[open] summary::after { content: " ↑"; }
.entry-details[open] summary { margin-bottom: 4px; }

.admin-entry {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    cursor: grab;
}
.admin-entry.is-top { background: var(--color-top); border-color: var(--color-top-border); }
.admin-entry .drag-handle { color: var(--color-muted); padding-top: 2px; user-select: none; }
.admin-entry .entry-main { flex: 1; min-width: 0; }
.admin-entry .entry-meta { font-size: 0.8rem; color: var(--color-muted); margin-bottom: 2px; }
.admin-entry .entry-headline-line { font-weight: 700; }
.admin-entry .entry-row-actions { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.admin-entry .entry-row-actions a { color: var(--color-accent); text-decoration: none; }
.admin-entry .entry-link-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 320px;
}
.admin-entry.sortable-ghost { opacity: 0.4; }

.sector-dropzone {
    min-height: 48px;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 8px;
}
.sector-empty-hint {
    margin: 0;
    padding: 6px 4px;
    color: var(--color-muted);
    font-size: 0.85rem;
    text-align: center;
}

table.admin-table { width: 100%; border-collapse: collapse; }
table.admin-table th, table.admin-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.92rem;
}
table.admin-table th { color: var(--color-muted); font-size: 0.8rem; text-transform: uppercase; }
table.admin-table .drag-handle { cursor: grab; color: var(--color-muted); }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input[type=text] { width: auto; flex: 1; }

.checkbox-line { display: flex; align-items: center; gap: 8px; margin: 0; }
.checkbox-line input { width: auto; }

.type-choice { display: flex; gap: 20px; margin: 6px 0 4px; }
.radio-line { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.radio-line input { width: auto; }

.field-hint { color: var(--color-muted); font-size: 0.85rem; margin: 4px 0 8px; }

.muted { color: var(--color-muted); font-size: 0.88rem; }

.table-wrap { overflow-x: auto; }

@media (max-width: 640px) {
    .page { padding: 16px 14px 48px; }
    h1 { font-size: 1.25rem; }
    header.site-header { padding: 12px 14px; }
    header.site-header .brand { font-size: 0.98rem; }

    .card { padding: 16px; }

    .date-bar { flex-direction: column; align-items: stretch; }
    .date-bar .btn, .date-bar .btn-secondary { text-align: center; }

    .type-choice { gap: 10px 20px; }

    .admin-entry { flex-wrap: wrap; }
    .admin-entry .entry-row-actions { flex-wrap: wrap; row-gap: 6px; }
    .admin-entry .entry-link-text { max-width: 100%; }

    .inline-form { flex-wrap: wrap; }
    .inline-form input[type=text] { width: 100%; }

    .actions { flex-wrap: wrap; }
    .actions button, .actions .btn { flex: 1; text-align: center; }

    .entry-meta-row { gap: 6px; }
    .entry-submitted { margin-left: 0; }

    table.admin-table { min-width: 480px; font-size: 0.85rem; }
    table.admin-table td, table.admin-table th { padding: 6px 8px; }
    .table-wrap .inline-form { flex-wrap: nowrap; }
    .table-wrap input[type=text] { width: auto; }
}
