/* Ecospez CRM — iOS-style clean interface */
*, *::before, *::after { box-sizing: border-box; }

/* iOS touch behavior: no gray tap highlight, no long-press callout */
html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}
a, button, [role="button"] {
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

:root {
    /* Colors */
    --green: #2d7a4f;
    --green-light: #e8f5ee;
    --gray-50: #f8f9fa;
    --gray-100: #e9ecef;
    --gray-200: #dee2e6;
    --gray-300: #dee2e6;
    --gray-600: #6c757d;
    --gray-800: #343a40;
    --danger: #dc3545;
    --warning: #ffc107;
    --success: #198754;

    /* iOS system colors */
    --ios-blue: #007aff;
    --ios-green: #34c759;
    --ios-red: #ff3b30;
    --ios-orange: #ff9500;
    --ios-yellow: #ffcc00;
    --ios-gray: #8e8e93;
    --ios-gray-2: #aeaeb2;
    --ios-gray-5: #e5e5ea;
    --ios-gray-6: #f2f2f7;
    --ios-separator: rgba(60,60,67,.12);

    /* iOS-style spacing & corners */
    --radius-card: 16px;
    --radius-card-lg: 20px;
    --radius-sm: 10px;
    --radius-btn-primary: 980px;
    --radius-pill: 980px;

    /* Shadows */
    --shadow: 0 1px 3px rgba(0,0,0,.06);
    --shadow-card: 0 4px 16px rgba(0,0,0,.06);
    --shadow-nav: 0 1px 0 rgba(0,0,0,.04);
    --shadow-float: 0 8px 28px rgba(0,0,0,.12);

    /* Backgrounds & borders */
    --bg-page: #f2f2f7;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --border-subtle: rgba(0,0,0,.06);

    /* Typography */
    --font-size-base: 15px;

    /* iOS easing */
    --ease-ios: cubic-bezier(.33,1,.68,1);
    --ease-ios-in: cubic-bezier(.32,0,.67,0);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--gray-800);
    margin: 0;
    background: var(--bg-page);
    /* Safe area for iPhone notch / home indicator */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    -webkit-font-smoothing: antialiased;
}

/* NAV — iOS frosted-glass sticky bar */
nav {
    background: rgba(255,255,255,.82);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
    color: var(--gray-800);
    border-bottom: 1px solid var(--ios-separator);
    box-shadow: var(--shadow-nav);
    padding-top: env(safe-area-inset-top);
    position: sticky;
    top: 0;
    z-index: 50;
}

.nav-top {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .6rem 1.5rem;
}

.nav-collapsible {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.5rem .6rem;
}

/* Desktop: merge nav-top and nav-collapsible into single row */
@media (min-width: 769px) {
    nav {
        display: flex;
        align-items: center;
        gap: 1.5rem;
        padding: .6rem 1.5rem;
    }
    .nav-top {
        padding: 0;
        gap: 1.5rem;
    }
    .nav-collapsible {
        padding: 0;
    }
    .nav-toggle {
        display: none;
    }
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--gray-800);
    font-size: 1.6rem;
    cursor: pointer;
    padding: .3rem .6rem;
    margin-left: auto;
    min-width: 44px;
    min-height: 44px;
    line-height: 1;
    border-radius: var(--radius-sm);
}

.nav-toggle:active {
    background: var(--gray-100);
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--green);
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 1rem;
    margin: 0;
    padding: 0;
    flex: 1;
}

.nav-links a {
    color: var(--gray-800);
    text-decoration: none;
    padding: .4rem .9rem;
    border-radius: var(--radius-pill);
    font-weight: 500;
    transition: background-color .18s var(--ease-ios), color .18s var(--ease-ios);
}

.nav-links a:hover {
    background: var(--ios-gray-5);
}

.nav-links a.active {
    background: var(--green);
    color: #fff;
}
.nav-links a.active:hover {
    background: #236040;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: .8rem;
    color: var(--gray-600);
    font-size: .85rem;
}

.btn-link {
    background: none;
    border: none;
    color: var(--gray-800);
    cursor: pointer;
    padding: 0;
    font-size: .85rem;
}

/* MAIN */
main {
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* PAGE HEADER — iOS large-title feel */
.page-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.4rem;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0;
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--gray-800);
}

/* CARD — iOS grouped section */
.card {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius-card);
    padding: 1.3rem 1.4rem;
    margin-bottom: 1.2rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.05);
}

.card > h2,
.card > h3 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--gray-800);
}

.card > h2 + dl,
.card > h2 + .ios-list {
    margin-top: .4rem;
}

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

.card-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -.01em;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* TABLE — iOS grouped-list look */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .9rem;
    background: var(--bg-card);
    border-radius: var(--radius-card);
    overflow: hidden;
}

.data-table th {
    background: var(--ios-gray-6);
    border-bottom: 1px solid var(--ios-separator);
    padding: .65rem .9rem;
    text-align: left;
    white-space: nowrap;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--gray-600);
}

.data-table td {
    border-bottom: 1px solid var(--ios-separator);
    padding: .6rem .9rem;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: background-color .12s var(--ease-ios);
}

.data-table tbody tr:hover td {
    background: var(--ios-gray-6);
}

.data-table td.empty {
    color: var(--gray-600);
    font-style: italic;
    text-align: center;
    padding: 1.5rem;
}

/* FORMS */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: .3rem;
    font-weight: 500;
}

input[type=text],
input[type=number],
input[type=password],
input[type=email],
input[type=search],
input[type=tel],
input[type=url],
input[type=date],
select,
textarea {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    /* 16px — minimum to prevent iOS Safari auto-zoom on focus */
    font-size: 16px;
    background: var(--bg-card);
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(45,122,79,.15);
}

textarea {
    resize: vertical;
}

.filter-form {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-form input,
.filter-form select {
    width: auto;
    min-width: 160px;
}

.inline-form {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-top: .8rem;
}

.inline-form input,
.inline-form select {
    width: auto;
}

.form-details summary {
    cursor: pointer;
    color: var(--green);
    font-weight: 500;
    margin-bottom: .8rem;
}

/* BUTTONS — iOS pill style */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .45rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    background: var(--ios-gray-5);
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--gray-800);
    white-space: nowrap;
    font-family: inherit;
    transition: background-color .18s var(--ease-ios),
                color .18s var(--ease-ios),
                transform .12s var(--ease-ios),
                opacity .12s var(--ease-ios);
}

.btn:hover {
    background: #dcdce1;
}
.btn:active {
    opacity: .55;
    transform: scale(.97);
}

.btn-primary {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
    padding: .5rem 1.3rem;
    box-shadow: 0 1px 2px rgba(45,122,79,.2);
}

.btn-primary:hover {
    background: #236040;
}

.btn-success {
    background: var(--ios-green);
    border-color: var(--ios-green);
    color: #fff;
}
.btn-success:hover { background: #28a745; }

.btn-danger {
    background: var(--ios-red);
    border-color: var(--ios-red);
    color: #fff;
}
.btn-danger:hover { background: #d63329; }

.btn-sm {
    padding: .3rem .75rem;
    font-size: .82rem;
}

.btn-full {
    width: 100%;
    text-align: center;
}

/* BADGES — iOS pill capsule */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .25rem .65rem;
    border-radius: var(--radius-pill);
    font-size: .74rem;
    font-weight: 600;
    background: var(--ios-gray-5);
    color: var(--gray-600);
    letter-spacing: .01em;
    line-height: 1.2;
}

.status-new                { background: #e3f2fd; color: #1565c0; }
.status-docs_received      { background: #e1f5fe; color: #01579b; }
.status-recognized         { background: #e0f7fa; color: #006064; }
.status-needs_review       { background: #fff8e1; color: #ff6f00; }
.status-wastes_matched     { background: #f1f8e9; color: #33691e; }
.status-calculated         { background: #f3e5f5; color: #6a1b9a; }
.status-kp_created         { background: #fff3e0; color: #e65100; }
.status-kp_approved        { background: #e8f5e9; color: #2e7d32; }
.status-contract_created   { background: #ede7f6; color: #4527a0; }
.status-contract_sent      { background: #e8eaf6; color: #3949ab; }
.status-contract_signed    { background: #e8f5e9; color: #2e7d32; }
.status-spec_created       { background: #e8eaf6; color: #283593; }
.status-act_created        { background: #fbe9e7; color: #bf360c; }
.status-act_sent           { background: #fff8e1; color: #f57f17; }
.status-act_signed         { background: #e8f5e9; color: #2e7d32; }
.status-awaiting_payment   { background: #fff3e0; color: #e65100; }
.status-completed          { background: #e8f5e9; color: #1b5e20; }
.status-declined           { background: #fce4ec; color: #b71c1c; }

/* iOS SEGMENTED TABS — pill-style content tabs */
.ios-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--ios-gray-6);
    border-radius: var(--radius-pill);
    margin-bottom: 1.2rem;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.ios-tabs::-webkit-scrollbar { display: none; }

.ios-tab {
    flex: 0 0 auto;
    padding: .5rem 1.1rem;
    border: none;
    background: transparent;
    color: var(--gray-800);
    font-size: .88rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    transition: background-color .18s var(--ease-ios),
                color .18s var(--ease-ios),
                box-shadow .18s var(--ease-ios),
                transform .12s var(--ease-ios);
    font-family: inherit;
}
.ios-tab:hover {
    color: var(--green);
}
.ios-tab:active {
    transform: scale(.97);
    opacity: .7;
}
.ios-tab.is-active {
    background: #fff;
    color: var(--gray-800);
    box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 3px 8px rgba(0,0,0,.06);
    font-weight: 600;
}

/* iOS SWITCH — toggle */
.ios-switch {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
    vertical-align: middle;
    flex-shrink: 0;
}
.ios-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.ios-switch .track {
    position: absolute;
    inset: 0;
    background: var(--ios-gray-5);
    border-radius: 31px;
    transition: background-color .2s var(--ease-ios);
    cursor: pointer;
}
.ios-switch .thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.1);
    transition: transform .22s var(--ease-ios);
}
.ios-switch input:checked ~ .track {
    background: var(--ios-green);
}
.ios-switch input:checked ~ .thumb {
    transform: translateX(20px);
}
.ios-switch input:focus-visible ~ .track {
    box-shadow: 0 0 0 3px rgba(52,199,89,.25);
}

/* iOS CHEVRON LIST — row with › at end */
.ios-list {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    overflow: hidden;
    list-style: none;
    padding: 0;
    margin: 0 0 1.2rem;
}
.ios-list > li,
.ios-list > .ios-row {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--ios-separator);
    color: var(--gray-800);
    text-decoration: none;
    min-height: 44px;
    transition: background-color .15s var(--ease-ios);
}
.ios-list > li:last-child,
.ios-list > .ios-row:last-child {
    border-bottom: none;
}
.ios-list > a:hover,
.ios-list > .ios-row:hover {
    background: var(--ios-gray-6);
}
.ios-list .ios-row-title {
    flex: 1;
    font-weight: 500;
}
.ios-list .ios-row-value {
    color: var(--gray-600);
    font-size: .88rem;
}
.ios-list .chevron::after {
    content: '›';
    color: var(--ios-gray);
    font-size: 1.4rem;
    line-height: 1;
    margin-left: .4rem;
    font-weight: 300;
}

/* STATUS STEPPER */
.status-stepper {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    padding: 4px;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-card);
}

/* ── 2×2 document grid ───────────────────────────────────────────────── */
.docs-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.docs-grid > .card {
    flex: 1 1 calc(50% - .5rem);
    min-width: 280px;
    margin-bottom: 0;
}
@media (max-width: 900px) {
    .docs-grid > .card { flex: 1 1 100%; }
}

/* ── Tab bar (Alpine.js tabs) ────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--ios-separator);
    margin-bottom: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
    flex: 0 0 auto;
    padding: .8rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1rem;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
    min-height: 44px;
}
.tab-btn:hover { color: var(--gray-800); }
.tab-btn-active {
    color: var(--green);
    border-bottom-color: var(--green);
}
[x-cloak] { display: none !important; }

/* ── Chip row (quick filters) ─────────────────────────────────────────── */
.chip-row {
    display: flex;
    gap: .5rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}
.chip {
    display: inline-flex;
    align-items: center;
    padding: .3rem .9rem;
    border-radius: 50px;
    font-size: .85rem;
    font-weight: 500;
    background: var(--gray-100);
    color: var(--gray-600);
    text-decoration: none;
    transition: background .15s, color .15s;
    border: 1px solid transparent;
}
.chip:hover { background: var(--gray-200); }
.chip-active {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}
.chip-active:hover { opacity: .9; }

.status-stepper .step {
    flex: 1 1 auto;
    min-width: 72px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: .45rem .35rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--gray-800);
    background: transparent;
    border: 1px solid transparent;
    transition: background-color .12s, border-color .12s;
    position: relative;
}

.status-stepper .step:hover {
    background: var(--bg-page);
}

.status-stepper .step .step-label {
    font-size: .68rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--gray-600);
}

.status-stepper .step .step-count {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-top: 2px;
}

.status-stepper .step-active {
    background: var(--green-light);
    border-color: var(--green);
}

.status-stepper .step-active .step-label {
    color: var(--green);
}

.status-stepper .step-active .step-count {
    color: var(--green);
}

.status-stepper .step-declined.step-active {
    background: #fce4ec;
    border-color: #b71c1c;
}

.status-stepper .step-declined.step-active .step-label,
.status-stepper .step-declined.step-active .step-count {
    color: #b71c1c;
}

/* Sticky filter panel */
.filters-sticky {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-page);
    padding: .6rem .5rem;
    margin: 0 -.5rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.filter-form-grid {
    gap: .4rem .5rem;
}

/* Sortable column headers */
.th-sort {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.th-sort:hover {
    color: var(--green);
}

.th-sort-active {
    color: var(--green);
    font-weight: 700;
}

/* Pager */
.pager {
    display: flex;
    align-items: center;
    gap: .8rem;
    margin-top: 1rem;
    justify-content: center;
}

.pager-info {
    color: var(--gray-600);
    font-size: .85rem;
}

.btn-disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.small {
    font-size: .85rem;
    font-weight: 400;
}

/* STATUS CARD (detail) — iOS stepper */
.status-card {
    padding: 1.1rem 1.2rem;
}

.status-pipeline {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 1rem;
    align-items: stretch;
}

.pipe-step {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .4rem .8rem .4rem .4rem;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    background: var(--ios-gray-6);
    color: var(--gray-600);
    font-size: .83rem;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    transition: background-color .18s var(--ease-ios), color .18s var(--ease-ios);
}

.pipe-step .pipe-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    background: var(--ios-gray-5);
    color: var(--gray-600);
    flex-shrink: 0;
}

.pipe-done {
    background: rgba(52,199,89,.12);
    color: #1b6b39;
}

.pipe-done .pipe-num {
    background: var(--ios-green);
    color: #fff;
}

.pipe-cur {
    background: var(--green);
    color: #fff;
    box-shadow: 0 2px 8px rgba(45,122,79,.28);
    font-weight: 600;
}

.pipe-cur .pipe-num {
    background: rgba(255,255,255,.22);
    color: #fff;
}

.pipe-declined {
    background: rgba(255,59,48,.12);
    color: #a1261e;
}

.pipe-declined .pipe-num {
    background: var(--ios-red);
    color: #fff;
}

.status-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    flex-wrap: wrap;
    border-top: 1px solid var(--ios-separator);
    padding-top: .8rem;
    margin-top: .3rem;
}

.status-current {
    display: flex;
    align-items: center;
    gap: .4rem;
}

.status-buttons {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    align-items: center;
}

/* Dropdown */
details.dropdown {
    position: relative;
}

details.dropdown summary {
    list-style: none;
    cursor: pointer;
    display: inline-block;
}

details.dropdown summary::-webkit-details-marker {
    display: none;
}

details.dropdown[open] summary {
    background: #236040;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 20;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    min-width: 220px;
    overflow: hidden;
}

.dropdown-item {
    width: 100%;
    text-align: left;
    border: none;
    background: var(--bg-card);
    color: var(--gray-800);
    padding: .5rem .8rem;
    cursor: pointer;
    font-size: .85rem;
    display: block;
    transition: background-color .12s;
}

.dropdown-item:hover {
    background: var(--green-light);
    color: var(--green);
}

/* Modal */
[x-cloak] {
    display: none !important;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 1.4rem 1.6rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 16px 48px rgba(0,0,0,.22);
}

.modal h3 {
    margin: 0 0 .4rem;
    font-size: 1.1rem;
}

.modal-actions {
    display: flex;
    gap: .6rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Delta (план/факт) */
.delta-plus {
    color: var(--success);
    font-weight: 600;
}

.delta-minus {
    color: var(--danger);
    font-weight: 600;
}

.row-added-on-act {
    background: #fff8e1;
}

.row-added-on-act:hover td {
    background: #ffecb3;
}

/* DL — iOS settings-style key-value list with row separators */
dl {
    display: grid;
    grid-template-columns: minmax(160px, max-content) 1fr;
    gap: 0;
    margin: 0;
}

dt, dd {
    padding: .65rem 0;
    border-bottom: 1px solid var(--ios-separator);
    align-self: center;
}

dt {
    color: var(--gray-600);
    font-weight: 500;
    font-size: .88rem;
    padding-right: 1rem;
}

dd {
    margin: 0;
    color: var(--gray-800);
    word-break: break-word;
}

dl > dt:last-of-type,
dl > dd:last-of-type {
    border-bottom: none;
}

/* When dl is last child of card, no trailing border gap */
.card > dl {
    margin-top: -.2rem;
}

/* Inline forms inside dl cells shouldn't stretch input-default width:100% */
dd form input[type=text],
dd form input[type=number],
dd form select,
dd form textarea {
    width: auto;
    font-size: .9rem;
    padding: .35rem .55rem;
}

dd form {
    display: inline-flex !important;
    gap: .35rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: .3rem;
}

/* ALERTS */
.alert {
    padding: .6rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

.alert-error {
    background: #fce4ec;
    color: #b71c1c;
    border: 1px solid #f48fb1;
}

.alert-success {
    background: #e8f5e9;
    color: #1b5e20;
    border: 1px solid #81c784;
}

/* LOGIN */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    padding: 2rem;
    width: 340px;
    box-shadow: var(--shadow-card);
}

.login-box h1 {
    margin: 0 0 .2rem;
    color: var(--green);
}

.login-box h2 {
    margin: 0 0 1.5rem;
    font-size: 1rem;
    color: var(--gray-600);
}

/* MISC */
.muted {
    color: var(--gray-600);
}

.filters {
    margin-bottom: 1rem;
}

.doc-list {
    list-style: none;
    padding: 0;
    margin: .5rem 0;
}

.doc-list li {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem 0;
    border-bottom: 1px solid var(--border-subtle);
}

.upload-form {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: .8rem;
}

.fragment-cell {
    max-width: 300px;
    word-break: break-word;
    font-size: .82rem;
    color: var(--gray-600);
}

.extracted-text {
    background: var(--bg-page);
    padding: 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: .82rem;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.confidence.high {
    color: var(--success);
    font-weight: 600;
}

.confidence.med {
    color: #e65100;
}

.confidence.low {
    color: var(--danger);
}

.match-table select {
    width: auto;
    min-width: 200px;
}

/* FKKO autocomplete */
.fkko-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow-card);
    max-height: 320px;
    overflow-y: auto;
}

.fkko-option {
    padding: .5rem .8rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    gap: .5rem;
    align-items: baseline;
    flex-wrap: wrap;
    width: 100%;
    border-left: 3px solid transparent;
    user-select: none;
    transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.fkko-option * {
    cursor: inherit;
    pointer-events: none;
}

.fkko-option:hover,
.fkko-option.is-hover,
.fkko-option:focus-within {
    background: #cbe8d8;
    border-left-color: var(--green);
    box-shadow: inset 0 0 0 1px rgba(45, 122, 79, .28);
}

.fkko-option:last-child {
    border-bottom: none;
}

.fkko-selected {
    margin-top: .4rem;
    padding: .4rem .7rem;
    background: var(--green-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .88rem;
    color: var(--green);
}

/* RESPONSIVE — mobile layout */
@media (max-width: 768px) {
    body {
        font-size: 15px;
    }

    /* Hamburger nav: collapsible hidden until menuOpen */
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .nav-collapsible {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: .4rem 1rem 1rem;
        border-top: 1px solid var(--border-subtle);
        margin-top: .6rem;
    }
    .nav-collapsible.is-open {
        display: flex;
    }
    .nav-links {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }
    .nav-links li {
        width: 100%;
    }
    .nav-links a {
        display: block;
        padding: .8rem .6rem;
        border-bottom: 1px solid var(--border-subtle);
        border-radius: 0;
        min-height: 44px;
    }
    .nav-links a.active {
        background: var(--green-light);
        border-bottom-color: var(--green);
    }
    .nav-user {
        flex-direction: column;
        align-items: stretch;
        gap: .5rem;
        padding-top: .8rem;
    }

    main {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* dl stacks vertically on narrow screens */
    dl {
        grid-template-columns: 1fr;
    }
    dt {
        padding-bottom: .15rem;
        border-bottom: none;
        font-size: .78rem;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--ios-gray);
    }
    dd {
        padding-top: 0;
        padding-bottom: .7rem;
    }

    .page-header h1 { font-size: 1.45rem; }
    .card { padding: 1.1rem; }

    /* Touch targets: Apple HIG minimum 44pt */
    .btn, .btn-sm, button[type="submit"], .nav-toggle {
        min-height: 44px;
    }
    .btn-sm {
        padding: .5rem .8rem;
        font-size: .9rem;
    }

    /* Horizontal scroll on wide tables with iOS momentum */
    .data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Slide-up sheet: modal rises from bottom instead of center popup */
    .modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }
    .modal {
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom));
        max-height: 90vh;
        overflow-y: auto;
        animation: slideUp .28s cubic-bezier(.33,1,.68,1);
    }
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    /* iOS-style drag handle */
    .modal::before {
        content: '';
        display: block;
        width: 38px;
        height: 4px;
        background: var(--gray-300);
        border-radius: 2px;
        margin: -.3rem auto .8rem;
    }

    .data-table {
        font-size: .8rem;
    }

    .data-table th {
        padding: .4rem .5rem;
    }

    .data-table td {
        padding: .3rem .5rem;
    }

    .modal {
        max-width: 90%;
    }

    .status-stepper {
        gap: 1px;
    }

    .status-stepper .step {
        min-width: 60px;
    }

    .status-stepper .step .step-label {
        font-size: .6rem;
    }

    .status-stepper .step .step-count {
        font-size: 1rem;
    }
}
