:root {
    --bg: #efe8db;
    --bg-deep: #d9cfbd;
    --surface: rgba(255, 252, 247, 0.82);
    --surface-strong: #fffaf3;
    --surface-muted: rgba(255, 247, 236, 0.72);
    --line: rgba(78, 56, 31, 0.14);
    --text: #2f2316;
    --text-soft: #6c5842;
    --accent: #c7602c;
    --accent-soft: #f0d0bf;
    --accent-strong: #8b3c17;
    --success: #1d7a5f;
    --warning: #a95c1b;
    --danger: #8b2e23;
    --shadow: 0 24px 80px rgba(71, 42, 18, 0.12);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --font-body: "Segoe UI Variable Text", "Trebuchet MS", "Arial Nova", sans-serif;
    --font-display: "Bahnschrift SemiBold", "Segoe UI Variable Display", "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(199, 96, 44, 0.14), transparent 30%),
        radial-gradient(circle at bottom right, rgba(76, 113, 143, 0.12), transparent 24%),
        linear-gradient(135deg, #f6efe3 0%, #ebe0ce 38%, #e4dac9 100%);
    background-attachment: fixed;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(72, 53, 31, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(72, 53, 31, 0.04) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(circle at center, black 45%, transparent 85%);
}

button, input, select, textarea {
    font: inherit;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent) 0%, #da7a3f 100%);
    color: white;
    padding: 0.8rem 1.1rem;
    font-family: var(--font-display);
    font-weight: 600;
    transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
    box-shadow: 0 10px 24px rgba(199, 96, 44, 0.24);
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
}

button:disabled {
    cursor: progress;
    opacity: 0.7;
}

button.ghost {
    background: rgba(255, 248, 240, 0.7);
    color: var(--text);
    box-shadow: none;
    border: 1px solid var(--line);
}

button.tiny {
    padding: 0.55rem 0.85rem;
    font-size: 0.88rem;
}

button.danger {
    color: var(--danger);
}

button.active {
    background: linear-gradient(135deg, var(--accent-strong) 0%, var(--accent) 100%);
    color: white;
}

input, select, textarea {
    width: 100%;
    border: 1px solid rgba(78, 56, 31, 0.16);
    background: rgba(255, 255, 255, 0.8);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 0.8rem 0.9rem;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
    resize: vertical;
}

input:focus, select:focus, textarea:focus {
    border-color: rgba(199, 96, 44, 0.55);
    box-shadow: 0 0 0 4px rgba(199, 96, 44, 0.12);
    background: white;
}

.shell {
    width: min(1800px, calc(100vw - 32px));
    margin: 16px auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    padding: 22px 26px;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, rgba(39, 28, 18, 0.92) 0%, rgba(79, 55, 31, 0.94) 60%, rgba(112, 75, 43, 0.92) 100%);
    color: #fff8ee;
    box-shadow: var(--shadow);
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 18px;
}

.brand-mark {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f0894c 0%, #c7602c 100%);
    color: white;
    font: 700 1.25rem var(--font-display);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.topbar h1,
.hero-card h2,
.panel h2,
.panel h3,
.panel h4 {
    font-family: var(--font-display);
    letter-spacing: 0.01em;
    margin: 0;
}

.brand-block p,
.topbar p {
    margin: 0;
    color: rgba(255, 248, 238, 0.75);
}

.topbar-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
    min-width: min(760px, 56vw);
}

.create-form {
    width: 100%;
    display: grid;
    grid-template-columns: 1.6fr 1fr 1.4fr auto;
    gap: 10px;
}

.create-form input {
    background: rgba(255, 250, 244, 0.9);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    font-size: 0.92rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
}

.status-saved {
    color: #caf0e2;
}

.status-error {
    color: #ffd0c6;
}

.error-banner {
    padding: 0.95rem 1.1rem;
    border-radius: var(--radius-md);
    background: rgba(139, 46, 35, 0.1);
    color: var(--danger);
    border: 1px solid rgba(139, 46, 35, 0.18);
}

.empty-state {
    display: grid;
    gap: 16px;
}

.hero-card,
.panel {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-xl);
    background: linear-gradient(180deg, var(--surface-strong) 0%, var(--surface) 100%);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.hero-card {
    padding: 36px;
    display: grid;
    gap: 14px;
}

.hero-card::after,
.panel::after {
    content: "";
    position: absolute;
    inset: auto -80px -80px auto;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(199, 96, 44, 0.12), transparent 70%);
}

.hero-card p {
    margin: 0;
    max-width: 900px;
    color: var(--text-soft);
}

.hero-actions,
.toolbar,
.export-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.projects-board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.workspace {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr) 360px;
    gap: 16px;
    align-items: start;
}

.sidebar,
.main-column,
.summary-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    padding: 20px;
    animation: rise-in 360ms ease;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-head.compact {
    margin-bottom: 12px;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--accent-strong);
}

.project-list,
.page-list,
.snapshot-list,
.summary-stack,
.pdf-file-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.project-card,
.page-chip,
.snapshot-item,
.summary-tile,
.calc-chip,
.metric-tile,
.preview-card,
.pdf-file {
    width: 100%;
    text-align: left;
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    border: 1px solid var(--line);
    box-shadow: none;
    color: var(--text);
}

.project-card,
.page-chip,
.calc-chip,
.pdf-file {
    padding: 1rem;
}

.project-card.active,
.page-chip.active,
.calc-chip.active {
    border-color: rgba(199, 96, 44, 0.34);
    background: linear-gradient(135deg, rgba(199, 96, 44, 0.16), rgba(255, 249, 243, 0.85));
}

.project-card strong,
.page-chip span,
.calc-chip-title,
.summary-tile strong,
.metric-tile strong,
.preview-card strong {
    display: block;
}

.project-card span,
.project-card small,
.page-chip small,
.snapshot-item small,
.calc-chip-meta,
.summary-tile small,
.metric-tile span,
.preview-card span,
.pdf-file small {
    color: var(--text-soft);
}

.page-chip {
    position: relative;
    padding-right: 2.8rem;
}

.page-chip-hit {
    position: absolute;
    inset: 0;
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.full-span {
    grid-column: 1 / -1;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field span {
    font-size: 0.92rem;
    color: var(--text-soft);
}

.checkbox-field {
    justify-content: center;
    gap: 12px;
    padding: 0.4rem 0;
}

.checkbox-field input {
    width: auto;
    margin: 0;
}

.inline-picker {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.metrics-grid,
.calc-preview {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.metric-tile,
.preview-card,
.summary-tile {
    padding: 1rem;
}

.preview-card.accent,
.summary-tile.accent {
    background: linear-gradient(135deg, rgba(199, 96, 44, 0.16), rgba(255, 245, 235, 0.92));
    border-color: rgba(199, 96, 44, 0.24);
}

.responsive-table {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255, 255, 255, 0.68);
}

th, td {
    padding: 0.85rem 0.9rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid rgba(78, 56, 31, 0.08);
}

th {
    position: sticky;
    top: 0;
    background: rgba(247, 236, 219, 0.95);
    font-family: var(--font-display);
    font-size: 0.88rem;
    color: var(--text-soft);
}

.calc-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
}

.calc-list,
.calc-editor {
    min-width: 0;
}

.calc-form,
.manual-list {
    display: grid;
    gap: 14px;
}

.manual-item {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius-md);
    background: rgba(255, 250, 244, 0.86);
    border: 1px solid var(--line);
}

.manual-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1.8rem;
}

.estimate-block {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.estimate-section-head,
.pdf-preview-head,
.estimate-total,
.pdf-preview footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.estimate-total,
.pdf-preview footer {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    font-family: var(--font-display);
}

.summary-panel .export-actions {
    margin-top: 14px;
}

.pdf-preview {
    padding: 8px;
    background: linear-gradient(180deg, rgba(240, 228, 212, 0.76), rgba(231, 220, 206, 0.58));
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
}

.pdf-sheet {
    background: white;
    color: #2c2c2c;
    border-radius: 18px;
    min-height: 420px;
    padding: 26px;
    box-shadow: 0 18px 42px rgba(37, 22, 12, 0.12);
    display: grid;
    gap: 14px;
}

.pdf-sheet header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    border-bottom: 1px solid #e5dfd5;
    padding-bottom: 10px;
}

.pdf-preview-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 12px;
    padding: 0.4rem 0;
    border-bottom: 1px dashed #ebe5db;
}

.pdf-file {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
}

.loading-screen {
    min-height: 70vh;
    display: grid;
    place-items: center;
    gap: 14px;
    color: var(--text-soft);
}

.spinner {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 4px solid rgba(199, 96, 44, 0.16);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

.empty-inline,
.muted {
    color: var(--text-soft);
}

.align-end {
    justify-content: flex-end;
}

.page-context {
    color: var(--text-soft);
    font-size: 0.92rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1380px) {
    .workspace {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .summary-column {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1.2fr;
    }
}

@media (max-width: 1120px) {
    .shell {
        width: min(100vw - 20px, 1600px);
        padding: 10px;
    }

    .topbar,
    .workspace {
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .topbar-actions,
    .create-form {
        width: 100%;
    }

    .create-form {
        grid-template-columns: 1fr 1fr;
    }

    .workspace {
        display: flex;
    }

    .project-grid,
    .metrics-grid,
    .calc-preview,
    .summary-column,
    .manual-item {
        grid-template-columns: 1fr 1fr;
    }

    .calc-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar {
        padding: 18px;
    }

    .create-form,
    .project-grid,
    .metrics-grid,
    .calc-preview,
    .summary-column,
    .manual-item,
    .inline-picker,
    .pdf-preview-row {
        grid-template-columns: 1fr;
    }

    .brand-block {
        align-items: flex-start;
    }

    .hero-card,
    .panel {
        padding: 16px;
    }

    .responsive-table table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table th,
    .responsive-table td,
    .responsive-table tr {
        display: block;
    }

    .responsive-table thead {
        display: none;
    }

    .responsive-table tr {
        padding: 12px;
        border-bottom: 1px solid var(--line);
    }

    .responsive-table td {
        padding: 0.35rem 0;
        border-bottom: none;
    }
}
