:root {
    --bg: #f4f1e8;
    --surface: #fffdfa;
    --surface-strong: #f2ead9;
    --text: #1f2933;
    --muted: #66717f;
    --line: #d8cdb7;
    --primary: #0f766e;
    --primary-strong: #115e59;
    --accent: #bb6b2d;
    --danger: #b42318;
    --success: #0f766e;
    --shadow: 0 18px 50px rgba(31, 41, 51, 0.12);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Trebuchet MS", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 32%),
        radial-gradient(circle at bottom right, rgba(187, 107, 45, 0.12), transparent 24%),
        var(--bg);
}

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

.muted {
    color: var(--muted);
}

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

.button,
button {
    border: 0;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    padding: 0.75rem 1.1rem;
    transition: transform 0.15s ease, background 0.15s ease;
}

.button:hover,
button:hover {
    background: var(--primary-strong);
    transform: translateY(-1px);
}

.button-secondary {
    background: var(--surface-strong);
    color: var(--text);
}

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

.link-button {
    background: none;
    color: var(--primary-strong);
    padding: 0;
}

.shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    background: rgba(255, 253, 250, 0.92);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--line);
    padding: 2rem 1.25rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand a {
    display: inline-block;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    margin-bottom: 1.5rem;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.nav a {
    padding: 0.8rem 1rem;
    border-radius: 14px;
    color: var(--text);
}

.nav a.active,
.nav a:hover {
    background: var(--surface-strong);
}

.main {
    min-width: 0;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 1.4rem 2rem 0;
}

.topbar-title {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.user-menu {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.content {
    padding: 1.5rem 2rem 2rem;
}

.card,
.auth-card,
.empty-state,
.stats-grid article,
.table-card,
.detail-grid,
.form-grid {
    background: var(--surface);
    border: 1px solid rgba(216, 205, 183, 0.8);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
}

.auth-card {
    width: min(480px, 100%);
    padding: 2rem;
}

.auth-card h1 {
    margin-top: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 1rem;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 0.8rem 0.95rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fff;
}

.field textarea {
    min-height: 110px;
    resize: vertical;
}

.field-error {
    color: var(--danger);
    font-size: 0.88rem;
}

.flash-stack {
    display: grid;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
}

.flash {
    padding: 0.9rem 1rem;
    border-radius: 14px;
}

.flash-success {
    background: rgba(15, 118, 110, 0.12);
    color: var(--success);
}

.flash-error {
    background: rgba(180, 35, 24, 0.12);
    color: var(--danger);
}

.toolbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
}

.toolbar form,
.toolbar .actions {
    display: flex;
    gap: 0.7rem;
    flex-wrap: wrap;
}

.table-card {
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid rgba(216, 205, 183, 0.8);
    vertical-align: top;
    text-align: left;
}

th {
    color: var(--muted);
    font-weight: 600;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.85rem;
    background: var(--surface-strong);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.4rem;
}

.stats-grid article {
    padding: 1.25rem;
}

.stats-grid strong {
    display: block;
    font-size: 1.6rem;
    margin-top: 0.6rem;
}

.split {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    padding: 1.2rem;
    margin-bottom: 1rem;
}

.detail-item strong {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
}

.panel {
    padding: 1.2rem;
    background: var(--surface);
    border: 1px solid rgba(216, 205, 183, 0.8);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel h2,
.panel h3 {
    margin-top: 0;
}

.panel + .panel {
    margin-top: 1rem;
}

.estimate-items {
    display: grid;
    gap: 0.8rem;
}

.estimate-positions,
.template-row-list {
    display: grid;
    gap: 1rem;
}

.estimate-item {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(244, 241, 232, 0.8));
}

.estimate-position,
.template-row {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(242, 234, 217, 0.75));
}

.estimate-item-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.8rem;
}

.estimate-position-grid,
.template-row-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
}

.select-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 0.5rem;
    align-items: center;
}

.compact-panel {
    padding: 0.9rem;
}

.compact-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0;
    box-shadow: none;
    border: 0;
    background: transparent;
    margin-top: 1rem;
}

.estimate-position-total {
    font-size: 1.3rem;
    font-weight: 700;
}

.template-row .field {
    margin-bottom: 0;
}

.field-actions {
    justify-content: flex-end;
}

.print-breakdown {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    padding: 1rem 0;
}

.empty-state {
    padding: 2rem;
    text-align: center;
}

ul {
    margin: 0;
    padding-left: 1.2rem;
}

.menu-toggle {
    display: none;
}

@media (max-width: 980px) {
    .shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        width: 280px;
        z-index: 30;
        transition: left 0.2s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .topbar,
    .content {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .grid-2,
    .split,
    .estimate-item-grid,
    .estimate-position-grid,
    .template-row-grid,
    .select-actions,
    .print-breakdown {
        grid-template-columns: 1fr;
    }

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

    thead {
        display: none;
    }

    tr {
        padding: 0.9rem;
        border-bottom: 1px solid rgba(216, 205, 183, 0.8);
    }

    td {
        border-bottom: 0;
        padding: 0.45rem 0;
    }
}
