:root {
    --bg: #f4f7fb;
    --surface: #eef3fb;
    --card: #ffffff;
    --raised: #f7faff;
    --line: rgba(26, 48, 86, 0.10);
    --line-s: rgba(26, 48, 86, 0.16);
    --accent: #4f6ef7;
    --accent-l: #355af1;
    --accent-bg: rgba(79, 110, 247, 0.10);
    --grad: linear-gradient(135deg, #4f6ef7, #6f8cff);
    --grad-soft: linear-gradient(180deg, rgba(79, 110, 247, 0.12), rgba(111, 140, 255, 0.04));
    --tx: #182235;
    --tx2: #4d5d79;
    --tx3: #7685a0;
    --tx4: #9ba8bc;
    --ok: #209866;
    --err: #d54d4d;
    --warn: #d08b1f;
    --r: 10px;
    --r2: 16px;
    --tr: 0.16s cubic-bezier(.4,0,.2,1);
    --sb: 310px;
    --font: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    color: var(--tx);
    background:
        radial-gradient(circle at top left, rgba(79, 110, 247, 0.08), transparent 24%),
        linear-gradient(180deg, #fbfcff 0%, var(--bg) 100%);
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); }
input, select, textarea, button { -webkit-appearance: none; appearance: none; }

.app-shell {
    display: grid;
    grid-template-columns: var(--sb) minmax(0, 1fr);
    min-height: 100vh;
}

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 18px;
    background:
        radial-gradient(circle at top left, rgba(79, 110, 247, 0.10), transparent 25%),
        linear-gradient(180deg, #f8fbff 0%, #edf3fb 100%);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

.app-main {
    padding: 30px 34px;
    min-height: 100vh;
}

.app-main-content {
    /* On desktop the padding comes from .app-main; this wrapper is layout-only */
}

.sb-brand,
.card,
.sb-footer-card,
.admin-badge {
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(245,249,255,0.98));
    border: 1px solid var(--line);
    box-shadow: 0 14px 32px rgba(73, 101, 145, 0.08);
}

.sb-brand {
    padding: 20px;
    border-radius: 22px;
}

.sb-brand-bretica {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    margin-bottom: 12px;
    line-height: 0.9;
}

.sb-brand-bretica-b {
    font-size: 54px;
    font-weight: 800;
    color: #ff7a00;
    letter-spacing: -0.05em;
}

.sb-brand-bretica-word {
    font-size: 34px;
    font-weight: 800;
    color: #182235;
    letter-spacing: -0.05em;
}

.sb-brand-bretica-dot {
    font-size: 34px;
    font-weight: 800;
    color: #ff7a00;
    transform: translateY(-1px);
}

.sb-brand-text strong {
    display: block;
    font-size: 26px;
    line-height: 1.02;
    letter-spacing: -0.03em;
}

.sb-brand-text span {
    display: block;
    margin-top: 9px;
    font-size: 12.5px;
    color: var(--tx2);
    line-height: 1.6;
}

.sb-brand-text small {
    display: block;
    margin-top: 10px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--tx3);
    line-height: 1.5;
}

.sb-nav {
    display: grid;
    gap: 10px;
    padding: 20px 0 14px;
    flex: 1;
}

.sb-menu-item {
    position: relative;
    border-radius: 20px;
    padding: 1px;
    background: linear-gradient(180deg, rgba(92, 117, 158, 0.08), rgba(92, 117, 158, 0.03));
    transition: transform var(--tr), box-shadow var(--tr), background var(--tr);
}

.sb-menu-item:hover {
    transform: translateX(3px);
    box-shadow: 0 16px 26px rgba(73, 101, 145, 0.12);
}

.sb-menu-item.active {
    background: linear-gradient(135deg, rgba(79, 110, 247, 0.32), rgba(111, 140, 255, 0.16));
    box-shadow: 0 18px 30px rgba(73, 101, 145, 0.16);
}

.sb-menu-button {
    display: block;
    min-height: 92px;
    padding: 16px;
    border-radius: 19px;
    background: linear-gradient(180deg, #ffffff 0%, #f6f9ff 100%);
    border: 1px solid rgba(26, 48, 86, 0.08);
    transition: background var(--tr), border-color var(--tr);
}

.sb-menu-item:hover .sb-menu-button {
    background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
    border-color: rgba(79, 110, 247, 0.12);
}

.sb-menu-item.active .sb-menu-button {
    background: linear-gradient(180deg, #f7faff 0%, #edf3ff 100%);
    border-color: rgba(79, 110, 247, 0.20);
}

.sb-menu-item.active .sb-menu-button::after {
    content: '';
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 0;
    height: 3px;
    border-radius: 999px;
    background: var(--grad);
}

.sb-link-title {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: var(--tx);
    letter-spacing: -0.02em;
}

.sb-link-meta {
    display: block;
    margin-top: 7px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--tx2);
}

.sb-footer {
    display: grid;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.sb-footer-card,
.admin-badge {
    padding: 14px;
    border-radius: 16px;
}

.sb-footer-label,
.admin-label,
.result-section-title,
.material-row-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--tx3);
}

.sb-footer-text {
    margin-top: 7px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--tx2);
}

.sb-inline-link {
    margin-top: 10px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent-l);
    font-size: 12px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.sb-inline-link:hover {
    text-decoration: underline;
}

.admin-badge span {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-l);
}

.sb-action {
    display: block;
    width: 100%;
    padding: 12px 14px;
    text-align: center;
    border-radius: 14px;
    border: 1px solid rgba(213, 77, 77, 0.18);
    background: #fff3f3;
    color: var(--err);
    font-size: 13px;
    font-weight: 700;
    transition: all var(--tr);
}

.sb-action:hover {
    background: #ffeaea;
    border-color: rgba(213, 77, 77, 0.24);
}

.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.page-desc {
    margin-top: 7px;
    max-width: 62ch;
    color: var(--tx2);
    line-height: 1.65;
}

.filter-card {
    margin-bottom: 18px;
}

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

.filter-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
    border-radius: var(--r2);
    padding: 22px;
}

.card-title {
    font-size: 14px;
    font-weight: 700;
}

.card-subtitle {
    margin-top: 4px;
    font-size: 12.5px;
    color: var(--tx2);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(17, 24, 39, 0.36);
    backdrop-filter: blur(5px);
}

.modal-card {
    width: min(100%, 520px);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(245,249,255,0.98));
    box-shadow: 0 20px 50px rgba(38, 56, 90, 0.20);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-close {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--tx2);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.modal-form {
    display: grid;
    gap: 12px;
}

.flash {
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
}

.flash.success {
    background: rgba(32, 152, 102, 0.08);
    border-color: rgba(32, 152, 102, 0.14);
    color: var(--ok);
}

.flash.error {
    background: rgba(213, 77, 77, 0.08);
    border-color: rgba(213, 77, 77, 0.14);
    color: var(--err);
}

.toast-stack {
    position: fixed;
    top: 22px;
    right: 22px;
    z-index: 80;
    display: grid;
    gap: 10px;
}

.toast {
    min-width: 280px;
    max-width: 360px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(245,249,255,0.98));
    box-shadow: 0 18px 40px rgba(38, 56, 90, 0.16);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity var(--tr), transform var(--tr);
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-color: rgba(32, 152, 102, 0.18);
}

.toast-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--tx);
}

.toast-text {
    margin-top: 4px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--tx2);
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) 360px;
    gap: 20px;
    align-items: start;
}

.result-panel {
    position: sticky;
    top: 30px;
}

.machine-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 14px;
    align-items: start;
}

.machine-picker-field {
    min-width: 0;
}

.machine-picker-panel {
    display: none;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
    box-shadow: 0 14px 28px rgba(73, 101, 145, 0.12);
    padding: 12px;
}

.machine-picker.is-open .machine-picker-panel {
    display: block;
}

.machine-picker-panel-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--tx3);
    margin-bottom: 10px;
}

.machine-picker-list {
    display: grid;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.machine-picker-item {
    width: 100%;
    text-align: left;
    padding: 11px 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fff;
    cursor: pointer;
    transition: border-color var(--tr), box-shadow var(--tr), transform var(--tr);
}

.machine-picker-item:hover {
    border-color: rgba(79, 110, 247, 0.24);
    box-shadow: 0 10px 20px rgba(73, 101, 145, 0.10);
    transform: translateY(-1px);
}

.machine-picker-item.is-selected {
    border-color: rgba(79, 110, 247, 0.28);
    background: #eef4ff;
}

.machine-picker-name,
.machine-picker-meta,
.machine-picker-sub {
    display: block;
}

.machine-picker-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--tx);
}

.machine-picker-meta,
.machine-picker-sub {
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--tx2);
}

.result-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.section-block {
    margin-bottom: 22px;
    padding-bottom: 22px;
    border-bottom: 1px solid var(--line);
}

.section-block:last-of-type {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: 0;
}

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

.section-title {
    font-size: 14px;
    font-weight: 700;
}

.section-copy {
    margin-top: 5px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--tx3);
}

.toggle-pills {
    display: flex;
    gap: 3px;
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.toggle-pill { position: relative; }

.toggle-pill input[type="radio"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.toggle-pill label {
    display: block;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--tx2);
}

.toggle-pill input:checked + label {
    background: #fff;
    color: var(--accent-l);
    box-shadow: 0 8px 20px rgba(73, 101, 145, 0.08);
}

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

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

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

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

.duration-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.duration-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--tx3);
}

.duration-box input[type="number"] {
    max-width: 110px;
    padding: 8px 10px;
}

.field-hint {
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--tx3);
}

label {
    font-size: 12px;
    font-weight: 600;
    color: var(--tx2);
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line-s);
    background: #fff;
    color: var(--tx);
    font: 13.5px/1.4 var(--font);
    outline: none;
    transition: border-color var(--tr), box-shadow var(--tr), background var(--tr);
}

input:hover,
select:hover,
textarea:hover {
    border-color: rgba(79, 110, 247, 0.18);
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(79, 110, 247, 0.34);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}

input[readonly] {
    background: #f3f7fc;
    color: var(--tx2);
}

select {
    cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, #7284a4 50%), linear-gradient(135deg, #7284a4 50%, transparent 50%);
    background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 32px;
}

textarea {
    min-height: 84px;
    resize: vertical;
}

::placeholder {
    color: var(--tx4);
}

.material-stack {
    display: grid;
    gap: 14px;
}

.material-row {
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--raised);
}

.material-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.material-remove-btn {
    width: auto;
    border: 0;
    background: transparent;
    color: var(--err);
    font-size: 12px;
    font-weight: 700;
    padding: 0;
}

.material-remove-btn:hover {
    text-decoration: underline;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--tr);
}

.btn-primary {
    color: #fff;
    background: var(--grad);
    box-shadow: 0 12px 22px rgba(79, 110, 247, 0.18);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 28px rgba(79, 110, 247, 0.24);
}

.btn-secondary {
    background: #eef4ff;
    color: var(--accent-l);
    border-color: rgba(79, 110, 247, 0.14);
}

.btn-secondary:hover {
    background: #e6eeff;
}

.btn-full {
    width: 100%;
    margin-top: 20px;
}

.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.metric-card {
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--raised);
}

.metric-card.primary {
    background: linear-gradient(180deg, #f7faff 0%, #edf3ff 100%);
    border-color: rgba(79, 110, 247, 0.12);
}

.m-label,
.t-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--tx3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.m-value {
    margin-top: 7px;
    font-size: 20px;
    font-weight: 700;
    color: var(--tx);
}

.summary-list {
    display: grid;
    gap: 8px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.s-label {
    color: var(--tx2);
}

.s-value {
    font-weight: 700;
    color: var(--tx);
}

.time-block {
    margin-top: 14px;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--raised);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.t-value {
    margin-top: 5px;
    font-size: 15px;
    font-weight: 700;
}

.empty-state {
    padding: 34px 20px;
    text-align: center;
}

.empty-title {
    font-size: 15px;
    font-weight: 700;
}

.empty-desc {
    margin: 8px auto 0;
    max-width: 30ch;
    font-size: 13px;
    color: var(--tx2);
    line-height: 1.6;
}

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

.extra-table,
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.extra-table {
    background: #fff;
}

.extra-table th,
.data-table th {
    padding: 10px 10px 8px;
    text-align: left;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--tx3);
}

.extra-table td {
    padding: 4px 6px;
}

.data-table th {
    background: #f4f8ff;
    border-bottom: 1px solid var(--line);
}

.data-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    color: var(--tx2);
    background: #fff;
}

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

.data-table td strong {
    color: var(--tx);
}

.source-link {
    color: var(--accent-l);
    font-weight: 700;
}

.suggestion-message {
    white-space: pre-wrap;
}

.suggestions-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: #f8fbff;
}

.suggestions-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--tx2);
}

.suggestion-check-col {
    width: 44px;
    text-align: center;
}

.suggestion-check-item {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.suggestion-check-item input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.suggestion-check-ui {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 1px solid rgba(79, 110, 247, 0.30);
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(24, 34, 53, 0.04);
    transition: background var(--tr), border-color var(--tr), box-shadow var(--tr);
}

.suggestion-check-item input:checked + .suggestion-check-ui {
    background: linear-gradient(135deg, #4f6ef7, #6f8cff);
    border-color: rgba(79, 110, 247, 0.60);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 18px;
    background:
        radial-gradient(circle at top left, rgba(255, 122, 0, 0.12), transparent 22%),
        radial-gradient(circle at bottom right, rgba(79, 110, 247, 0.10), transparent 24%),
        linear-gradient(180deg, #fbfcff 0%, #eef3fb 100%);
}

.login-card {
    width: min(100%, 460px);
    padding: 28px;
    border-radius: 28px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(244,248,255,0.98));
    box-shadow: 0 24px 60px rgba(38, 56, 90, 0.16);
}

.login-brand {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 18px;
}

.login-badge {
    display: inline-flex;
    align-items: center;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(79, 110, 247, 0.10);
    color: var(--accent-l);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.login-logo {
    margin-bottom: 18px;
}

.login-title {
    font-size: 29px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.05;
    color: var(--tx);
}

.login-sub {
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--tx2);
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-submit {
    min-height: 46px;
}

.login-hint {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(79, 110, 247, 0.08);
    color: var(--tx2);
    font-size: 12px;
    line-height: 1.6;
}

.back-link {
    display: inline-flex;
    align-items: center;
    margin-top: 16px;
    color: var(--accent-l);
    font-size: 12px;
    font-weight: 700;
}

.back-link:hover {
    text-decoration: underline;
}

.hp-field {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.flat-list {
    list-style: none;
    display: grid;
    gap: 8px;
}

.flat-list li {
    padding-left: 14px;
    position: relative;
    color: var(--tx2);
    line-height: 1.6;
}

.flat-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 9px;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--accent);
}

.muted { color: var(--tx3); }
.small { font-size: 12px; }
.is-hidden { display: none !important; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes countUp {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.result-appear {
    animation: countUp 0.28s ease both;
}

/* ============================================================
   MOBILE TOPBAR (hidden on desktop)
   ============================================================ */
.mobile-topbar   { display: none; }
.mobile-backdrop { display: none; }

/* ============================================================
   RESPONSIVE — intermediate (tablets / small desktops)
   ============================================================ */
@media (max-width: 1080px) {
    .content-grid,
    .two-col,
    .form-grid,
    .duration-grid,
    .filter-grid,
    .filter-grid-3,
    .metric-grid,
    .time-block {
        grid-template-columns: 1fr;
    }

    .machine-picker {
        grid-template-columns: 1fr;
    }

    .result-panel {
        position: static;
    }

    .stats-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-bottom-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   RESPONSIVE — mobile drawer (phones + tablets ≤ 900px)
   ============================================================ */
@media (max-width: 900px) {

    /* App shell: no sidebar column */
    .app-shell {
        display: block;
    }

    /* Sidebar: slide-in drawer */
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(var(--sb), 88vw);
        height: 100dvh;
        z-index: 400;
        transform: translateX(-110%);
        transition: transform 0.26s cubic-bezier(.4,0,.2,1);
        border-right: 1px solid var(--line);
        box-shadow: 6px 0 40px rgba(16, 30, 60, 0.16);
        overflow-y: auto;
    }

    .app-sidebar.is-open {
        transform: translateX(0);
    }

    /* Backdrop */
    .mobile-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 399;
        background: rgba(10, 20, 40, 0.45);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.26s ease;
    }

    .mobile-backdrop.is-visible {
        opacity: 1;
        pointer-events: all;
    }

    /* Mobile topbar */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,251,255,0.98));
        border-bottom: 1px solid var(--line);
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .mobile-brand {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .mobile-brand-b {
        font-size: 1.5rem;
        font-weight: 800;
        color: #e96c2a;
        line-height: 1;
        letter-spacing: -1px;
    }

    .mobile-brand-word {
        font-size: 1rem;
        font-weight: 700;
        color: var(--tx);
        line-height: 1;
    }

    .mobile-brand-dot {
        font-size: 1rem;
        font-weight: 800;
        color: var(--accent);
        line-height: 1;
    }

    .mobile-brand-label {
        font-size: .72rem;
        color: var(--tx4);
        font-weight: 500;
        margin-left: 8px;
        padding-left: 8px;
        border-left: 1px solid var(--line-s);
    }

    /* Hamburger button */
    .mobile-menu-btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        padding: 11px;
        background: none;
        border: none;
        cursor: pointer;
        border-radius: var(--r);
        transition: background var(--tr);
    }

    .mobile-menu-btn:hover,
    .mobile-menu-btn:active {
        background: var(--surface);
    }

    .mobile-menu-btn span {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--tx);
        border-radius: 2px;
        transition: transform 0.22s ease, opacity 0.22s ease;
        transform-origin: center;
    }

    .mobile-menu-btn.is-active span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .mobile-menu-btn.is-active span:nth-child(2) {
        opacity: 0;
        transform: scaleX(0);
    }

    .mobile-menu-btn.is-active span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Main content area */
    .app-main {
        padding: 0;
        min-height: 100dvh;
    }

    .app-main-content {
        padding: 20px 16px 48px;
    }

    /* Touch-friendly inputs — 16px prevents iOS auto-zoom */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        min-height: 46px;
        font-size: 16px;
    }

    textarea {
        min-height: 100px;
    }

    /* Buttons */
    .btn {
        min-height: 46px;
        font-size: .94rem;
    }

    .section-head .btn,
    .section-head .btn-secondary {
        width: 100%;
    }

    /* Section head stacks on mobile */
    .section-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    /* Duration inputs — extra large for touch */
    .duration-grid {
        gap: 10px;
    }

    .duration-box input {
        min-height: 52px;
        text-align: center;
        font-size: 1.15rem;
        font-weight: 600;
    }

    .duration-label {
        font-size: .8rem;
        text-align: center;
        display: block;
        margin-bottom: 4px;
    }

    /* Toggle pills — larger tap area */
    .toggle-pills {
        width: 100%;
    }

    .toggle-pill {
        flex: 1;
    }

    .toggle-pill label {
        min-height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 10px;
        font-size: .9rem;
    }

    /* Machine picker items */
    .machine-picker-item {
        padding: 14px 16px;
    }

    .machine-picker-name {
        font-size: .95rem;
    }

    /* Material rows */
    .material-remove-btn {
        min-height: 38px;
        min-width: 64px;
        font-size: .85rem;
        padding: 0 12px;
    }

    /* Extra supplies table */
    .extra-table th,
    .extra-table td {
        padding: 8px 6px;
    }

    .extra-table input {
        min-height: 44px;
        font-size: 16px;
    }

    /* Result metrics */
    .metric-value {
        font-size: 1.6rem;
    }

    /* Page header */
    .page-header {
        margin-bottom: 18px;
    }

    .page-title {
        font-size: 1.3rem;
    }

    /* Card padding */
    .card {
        padding: 20px 18px;
    }

    /* Flash inside content wrapper */
    .flash {
        margin-bottom: 16px;
    }

}

/* ============================================================
   RESPONSIVE — small phones (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
    .app-main-content {
        padding: 16px 12px 48px;
    }

    .stats-kpi-grid {
        grid-template-columns: 1fr;
    }

    .metric-value {
        font-size: 1.4rem;
    }

    .mobile-brand-label {
        display: none;
    }
}

/* ============================================================
   PRIVACY POLICY
   ============================================================ */
.privacy-section {
    border-bottom: 1px solid var(--line);
    padding-bottom: 24px;
    margin-bottom: 24px;
}

.privacy-heading {
    font-size: 1rem;
    font-weight: 700;
    color: var(--tx);
    margin-bottom: 10px;
}

.privacy-subheading {
    font-size: .88rem;
    font-weight: 600;
    color: var(--tx2);
    margin: 16px 0 6px;
}

.privacy-section p {
    color: var(--tx2);
    font-size: .9rem;
}

.sb-footer-privacy {
    text-align: center;
    padding: 8px 0 4px;
}

.sb-footer-privacy a {
    font-size: .74rem;
    color: var(--tx4);
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color var(--tr);
}

.sb-footer-privacy a:hover {
    color: var(--tx2);
}

/* ============================================================
   STATS PAGE
   ============================================================ */
.stats-kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stats-kpi-card {
    padding: 22px 24px;
    border-radius: var(--r2);
}

.stats-kpi-label {
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--tx3);
    margin-bottom: 8px;
}

.stats-kpi-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--tx);
    line-height: 1;
    margin-bottom: 6px;
}

.stats-kpi-sub {
    font-size: .78rem;
    color: var(--tx4);
}

.stats-kpi-accent .stats-kpi-value {
    color: var(--accent);
}

.stats-bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ============================================================
   PRINT MEDIA
   ============================================================ */
@media print {
    body {
        background: #fff;
    }

    .app-sidebar,
    .page-header,
    .content-grid > section,
    .no-print {
        display: none !important;
    }

    .app-shell,
    .app-main,
    .content-grid {
        display: block;
        padding: 0;
        margin: 0;
        min-height: auto;
    }

    .result-panel,
    .print-results,
    .metric-card,
    .time-block,
    .summary-row {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .result-panel {
        position: static;
        top: auto;
        border: 0;
        box-shadow: none;
        padding: 0 !important;
        background: #fff;
    }

    .card,
    .metric-card,
    .time-block {
        box-shadow: none;
        background: #fff;
    }
}
