:root {
    --bg: #f3f0e8;
    --panel: #fffdf8;
    --panel-alt: #efe7d8;
    --text: #1f1c18;
    --muted: #6f665b;
    --line: #d7ccbb;
    --primary: #1f6f5f;
    --primary-dark: #13483d;
    --warning: #c07a12;
    --danger: #b54838;
    --shadow: 0 18px 45px rgba(49, 40, 26, 0.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(31, 111, 95, 0.15), transparent 25%),
        linear-gradient(135deg, #f5f1e8, #ece5d7 55%, #dfd6c5);
    color: var(--text);
    font-family: Georgia, "Times New Roman", serif;
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 300px 1fr; }
.auth-shell { grid-template-columns: 1fr; }
.sidebar {
    padding: 32px 24px;
    background: rgba(31, 28, 24, 0.95);
    color: #f8f4eb;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 24px;
}
.sidebar h1, .content h2, .content h3 { margin: 0; font-family: Cambria, Georgia, serif; }
.nav { display: grid; gap: 10px; }
.nav a {
    color: #f8f4eb;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
}
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, 0.16); text-decoration: none; }
.content { padding: 28px; display: grid; gap: 24px; }
.page-header, .section-heading, .detail-grid, .stats-grid, .filters-grid, .form-grid, .form-actions, .header-actions { gap: 16px; }
.page-header, .section-heading { display: flex; justify-content: space-between; align-items: end; }
.stats-grid, .detail-grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.detail-grid { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.panel, .stat-card, .alert {
    background: var(--panel);
    border: 1px solid rgba(145, 126, 94, 0.18);
    border-radius: 22px;
    box-shadow: var(--shadow);
}
.panel, .alert, .stat-card { padding: 22px; }
.stat-card { background: linear-gradient(180deg, #fffaf0, #f8efe0); }
.stat-card span, .eyebrow, .muted, label span, dt { color: var(--muted); }
.stat-card strong { display: block; margin-top: 8px; font-size: 2rem; }
.eyebrow { margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; }
.muted { margin: 4px 0 0; }
.primary-button, .link-button { appearance: none; border: none; border-radius: 14px; cursor: pointer; }
.primary-button { background: var(--primary); color: white; padding: 12px 18px; }
.primary-button:hover { background: var(--primary-dark); }
.secondary-button { appearance: none; border: 1px solid var(--line); border-radius: 14px; cursor: pointer; background: #fffefb; color: var(--text); padding: 12px 18px; }
.link-button { background: transparent; color: #f8f4eb; padding: 0; }
.user-card {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: start;
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
}
.alert.success { border-left: 6px solid var(--primary); }
.alert.danger { border-left: 6px solid var(--danger); }
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--panel-alt);
    color: var(--text);
    font-size: 0.84rem;
    margin-right: 6px;
}
.badge.warning { background: rgba(192, 122, 18, 0.12); color: var(--warning); }
.badge.danger { background: rgba(181, 72, 56, 0.12); color: var(--danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 14px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
.filters-grid, .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid.compact { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.wide, .full { grid-column: 1 / -1; }
label { display: grid; gap: 8px; }
input, select, textarea {
    width: 100%;
    border-radius: 14px;
    border: 1px solid var(--line);
    padding: 12px 14px;
    background: #fffefb;
}
.inline { display: flex; align-items: center; }
.inline input { width: auto; }
.filter-actions, .form-actions { display: flex; align-items: end; flex-wrap: wrap; }
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 18px; margin: 0; }
dt { font-size: 0.9rem; }
dd { margin: 6px 0 0; }
.timeline { display: grid; gap: 14px; }
.timeline-item { border-left: 3px solid var(--panel-alt); padding-left: 14px; }
.timeline-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.timeline.minimal .timeline-item { background: #fffaf2; border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 16px; padding: 14px 16px; }
.handoff-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 18px; }
.handoff-card { padding: 16px; border-radius: 18px; background: linear-gradient(180deg, #f7efe2, #fff9ef); border: 1px solid var(--line); }
.primary-document { margin-bottom: 18px; padding: 16px; border-radius: 18px; background: linear-gradient(180deg, #eff6ef, #fbfffb); border: 1px solid #bfd0bf; }
.preview-actions { margin-top: 12px; }
.document-preview-frame { margin-top: 16px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: #f4f1ea; }
.document-preview-frame iframe { width: 100%; height: 560px; border: none; }
.documents-list { display: grid; gap: 12px; }
.document-group { padding: 18px 0; border-bottom: 1px solid var(--line); }
.document-group:last-child { border-bottom: none; padding-bottom: 0; }
.document-row { display: flex; justify-content: space-between; gap: 16px; align-items: start; padding: 16px 0; border-bottom: 1px solid var(--line); }
.document-row:last-child { border-bottom: none; padding-bottom: 0; }
.document-actions { display: flex; gap: 10px; align-items: start; flex-wrap: wrap; }
.version-list { margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--line); }
.version-list summary { cursor: pointer; color: var(--primary-dark); font-weight: 600; }
.version-items { display: grid; gap: 10px; margin-top: 12px; }
.version-item { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid rgba(215, 204, 187, 0.6); }
.version-item:last-child { border-bottom: none; }
.auth-panel { max-width: 560px; }
.stack { display: grid; gap: 14px; }
.credentials ul { margin-bottom: 0; }
.pagination nav { display: flex; justify-content: center; }
.breadcrumb { display: flex; gap: 6px; align-items: center; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--primary-dark); }
.breadcrumb .sep { color: var(--line); }
label.has-error input, label.has-error select, label.has-error textarea { border-color: var(--danger); background: rgba(181, 72, 56, 0.04); }
.field-error { color: var(--danger); font-size: 0.82rem; margin: 0; }
.timeline.minimal .timeline-item.timeline-created { border-left-color: var(--primary); }
.timeline.minimal .timeline-item.timeline-transfer { border-left-color: #3b6cb7; }
.timeline.minimal .timeline-item.timeline-updated { border-left-color: var(--muted); }
.timeline.minimal .timeline-item.timeline-closed { border-left-color: var(--danger); }
.timeline.minimal .timeline-item.timeline-document_added { border-left-color: var(--warning); }
.timeline.minimal .timeline-item.timeline-document_marked_primary { border-left-color: var(--warning); }
.timeline-event-type { display: inline-block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; margin-bottom: 4px; color: var(--muted); }

/* Action tabs */
.action-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 22px; padding-bottom: 0; }
.action-tab {
    appearance: none; border: none; background: transparent;
    padding: 10px 18px; border-radius: 12px 12px 0 0;
    cursor: pointer; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: color 0.15s, background 0.15s;
}
.action-tab:hover:not(.active) { background: var(--panel-alt); color: var(--text); }
.action-tab.active { background: var(--primary); color: white; border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Danger button variant */
.danger-button { background: var(--danger) !important; }
.danger-button:hover { background: #8f3028 !important; }

/* Form section headers */
.form-section-header {
    grid-column: 1 / -1;
    display: flex; align-items: center; gap: 12px;
    margin-top: 8px;
}
.form-section-header:first-child { margin-top: 0; }
.form-section-header span {
    font-size: 0.75rem; text-transform: uppercase;
    letter-spacing: 0.14em; font-weight: 700;
    color: var(--primary-dark); white-space: nowrap;
}
.form-section-header::after {
    content: ''; flex: 1;
    height: 1px; background: var(--line);
}

/* Optional label hint */
.form-optional { font-size: 0.78rem; font-weight: 400; color: var(--muted); }

/* Empty states */
.empty-state { padding: 32px 16px; text-align: center; }
.empty-state-title { font-size: 1rem; font-weight: 600; margin: 0 0 6px; }
.empty-state .muted { margin: 0; }

@media (max-width: 1100px) {
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { padding-bottom: 20px; }
    .document-row { flex-direction: column; }
    .version-item { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .action-tabs { gap: 2px; }
    .action-tab { padding: 8px 12px; font-size: 0.9rem; }
}
@media (max-width: 600px) {
    .content { padding: 16px; gap: 16px; }
    .panel, .alert, .stat-card { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid, .filters-grid { grid-template-columns: 1fr; }
    .form-grid.compact { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: start; }
}
