:root {
    --bg: #f4efe6;
    --panel: #fffdf9;
    --panel-strong: #f8f1e4;
    --line: #d8c7ae;
    --text: #241b13;
    --muted: #6e5f52;
    --accent: #b95528;
    --accent-dark: #893d1a;
    --success: #2f6b3f;
    --warning: #8a6820;
    --danger: #9b2d30;
    --shadow: 0 18px 40px rgba(70, 38, 18, 0.08);
}

:root[data-theme="dark"] {
    --bg: #0f1113;
    --panel: #181c20;
    --panel-strong: #20262b;
    --line: #313941;
    --text: #f2efe8;
    --muted: #b7b1a7;
    --accent: #e77d42;
    --accent-dark: #ffb58b;
    --success: #8ed7a9;
    --warning: #f0c768;
    --danger: #ff8f8f;
    --shadow: 0 20px 48px rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(185, 85, 40, 0.14), transparent 32%),
        linear-gradient(180deg, #f8f2e8 0%, var(--bg) 100%);
    color: var(--text);
}

:root[data-theme="dark"] body {
    background:
        radial-gradient(circle at top left, rgba(231, 125, 66, 0.12), transparent 26%),
        radial-gradient(circle at top right, rgba(90, 141, 214, 0.08), transparent 24%),
        linear-gradient(180deg, #101317 0%, var(--bg) 100%);
}

a {
    color: var(--accent-dark);
}

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

.site-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(137, 61, 26, 0.14);
    background: rgba(255, 253, 249, 0.82);
    backdrop-filter: blur(10px);
}

:root[data-theme="dark"] .site-header {
    border-bottom-color: rgba(255, 181, 139, 0.14);
    background: rgba(15, 18, 22, 0.88);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-center {
    display: flex;
    justify-content: center;
    flex: 1;
}

.refresh-button {
    min-width: 150px;
}

.page {
    max-width: 1460px;
    margin: 0 auto;
    padding: 2rem;
}

.site-footer {
    display: flex;
    justify-content: center;
    padding: 0.75rem 1rem 1.5rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.75rem;
    font-weight: 700;
}

h1, h2, h3, p {
    margin-top: 0;
}

.hero-panel,
.panel,
.auth-card {
    background: var(--panel);
    border: 1px solid rgba(137, 61, 26, 0.12);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

:root[data-theme="dark"] .hero-panel,
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .auth-card {
    border-color: rgba(255, 181, 139, 0.08);
}

.hero-panel,
.panel {
    padding: 1.5rem;
}

.hero-panel {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.hero-inline-info {
    margin-top: 1.2rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(137, 61, 26, 0.12);
}

:root[data-theme="dark"] .hero-inline-info {
    border-top-color: rgba(255, 181, 139, 0.1);
}

.pending-box {
    padding: 1rem 1.2rem;
    border-radius: 18px;
    background: var(--panel-strong);
    display: grid;
    gap: 0.4rem;
}

.grid-two {
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.grid-single {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.search-bar-section {
    margin-bottom: 1.5rem;
}

.search-panel {
    max-width: 760px;
    margin: 0 auto;
}

.search-label {
    display: grid;
    gap: 0.45rem;
}

.search-input {
    font-size: 1rem;
}

.request-entry-panel {
    max-width: 520px;
    width: 100%;
}

.request-entry-toggle {
    padding-top: 1rem;
}

.request-entry-summary {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 800;
    list-style: none;
}

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

.request-entry-summary::before {
    content: "▸";
    color: var(--accent-dark);
    transition: transform 0.15s ease;
}

.request-entry-toggle[open] .request-entry-summary::before {
    transform: rotate(90deg);
}

.request-entry-form {
    margin-top: 1.2rem;
}

.auth-card {
    max-width: 460px;
    padding: 2rem;
    margin: 4rem auto;
}

.form-grid {
    display: grid;
    gap: 1rem;
}

.button-row {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.position-builder {
    display: grid;
    gap: 0.7rem;
}

.position-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    min-height: 48px;
    padding: 0.75rem 0.9rem;
    border: 1px dashed var(--line);
    border-radius: 16px;
    background: rgba(248, 241, 228, 0.4);
}

:root[data-theme="dark"] .position-chip-list {
    background: rgba(255, 181, 139, 0.03);
    border-color: rgba(255, 181, 139, 0.16);
}

.position-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid rgba(137, 61, 26, 0.16);
    color: var(--text);
    font-weight: 700;
}

:root[data-theme="dark"] .position-chip {
    background: #10161b;
    border-color: rgba(255, 181, 139, 0.14);
    color: var(--text);
}

:root[data-theme="dark"] .position-chip span {
    color: var(--text);
}

.position-builder-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.whole-order-toggle {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-weight: 600;
}

.whole-order-toggle input {
    width: auto;
}

.machine-picker {
    margin: 0;
    padding: 0;
    border: 0;
    display: grid;
    gap: 0.7rem;
}

.machine-picker legend {
    padding: 0;
    font-weight: 600;
}

.machine-checkbox-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}

.machine-checkbox-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 52px;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(137, 61, 26, 0.16);
    border-radius: 16px;
    background: rgba(248, 241, 228, 0.45);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.machine-checkbox-item:hover {
    transform: translateY(-1px);
    border-color: rgba(137, 61, 26, 0.28);
}

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

.machine-checkbox-item span {
    font-weight: 700;
}

:root[data-theme="dark"] .machine-checkbox-item {
    background: rgba(255, 181, 139, 0.04);
    border-color: rgba(255, 181, 139, 0.14);
}

:root[data-theme="dark"] .machine-checkbox-item:hover {
    border-color: rgba(255, 181, 139, 0.28);
}

.machine-checkbox-item:has(input:checked) {
    background: rgba(185, 85, 40, 0.12);
    border-color: rgba(185, 85, 40, 0.55);
}

:root[data-theme="dark"] .machine-checkbox-item:has(input:checked) {
    background: rgba(231, 125, 66, 0.14);
    border-color: rgba(255, 181, 139, 0.45);
}

.position-note-list {
    display: grid;
    gap: 0.8rem;
}

.position-note-item {
    display: grid;
    gap: 0.4rem;
    padding: 0.85rem 0.95rem;
    border: 1px solid rgba(137, 61, 26, 0.12);
    border-radius: 16px;
    background: rgba(248, 241, 228, 0.38);
}

.position-note-item textarea {
    min-height: 78px;
}

:root[data-theme="dark"] .position-note-item {
    background: rgba(255, 181, 139, 0.04);
    border-color: rgba(255, 181, 139, 0.1);
}

.small-text {
    font-size: 0.84rem;
}

label {
    display: grid;
    gap: 0.45rem;
    font-weight: 600;
}

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

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
    background: #11161a;
    color: var(--text);
    border-color: #38414a;
}

:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
    color: #8f9aa3;
}

:root[data-theme="dark"] input:focus,
:root[data-theme="dark"] select:focus,
:root[data-theme="dark"] textarea:focus {
    outline: none;
    border-color: rgba(231, 125, 66, 0.8);
    box-shadow: 0 0 0 3px rgba(231, 125, 66, 0.16);
}

textarea {
    resize: vertical;
}

button,
.ghost-button {
    border: 0;
    border-radius: 999px;
    padding: 0.85rem 1.25rem;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

button {
    background: var(--accent);
    color: white;
}

:root[data-theme="dark"] button {
    color: #101317;
}

button:hover,
.ghost-button:hover {
    transform: translateY(-1px);
}

.ghost-button {
    background: transparent;
    border: 1px solid rgba(137, 61, 26, 0.2);
    color: var(--accent-dark);
}

:root[data-theme="dark"] .ghost-button {
    background: rgba(255, 181, 139, 0.04);
    border-color: rgba(255, 181, 139, 0.16);
    color: var(--accent-dark);
}

:root[data-theme="dark"] .ghost-button,
:root[data-theme="dark"] .ghost-button:visited,
:root[data-theme="dark"] .theme-toggle,
:root[data-theme="dark"] .theme-toggle:visited {
    color: var(--accent-dark);
}

:root[data-theme="dark"] .danger-button {
    color: #1a0d0d;
}

:root[data-theme="dark"] .small-button {
    color: #101317;
}

:root[data-theme="dark"] .header-nav a,
:root[data-theme="dark"] .header-nav a:visited {
    color: var(--accent-dark);
}

:root[data-theme="dark"] .request-entry-summary,
:root[data-theme="dark"] .search-label,
:root[data-theme="dark"] label,
:root[data-theme="dark"] h1,
:root[data-theme="dark"] h2,
:root[data-theme="dark"] h3 {
    color: var(--text);
}

:root[data-theme="dark"] .muted {
    color: #c8c1b7;
}

:root[data-theme="dark"] .small-text {
    color: #c8c1b7;
}

.small-button,
.danger-button {
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    font-size: 0.92rem;
}

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

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

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

.flash {
    padding: 0.95rem 1rem;
    border-radius: 16px;
    border: 1px solid transparent;
}

.flash-success {
    background: rgba(47, 107, 63, 0.1);
    border-color: rgba(47, 107, 63, 0.25);
}

.flash-error {
    background: rgba(155, 45, 48, 0.1);
    border-color: rgba(155, 45, 48, 0.25);
}

:root[data-theme="dark"] .flash-success {
    background: rgba(142, 215, 169, 0.1);
    border-color: rgba(142, 215, 169, 0.18);
}

:root[data-theme="dark"] .flash-error {
    background: rgba(255, 143, 143, 0.1);
    border-color: rgba(255, 143, 143, 0.18);
}

.section-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.section-head-stack {
    align-items: flex-start;
}

.table-wrap {
    overflow-x: auto;
}

.compact-table-wrap {
    overflow-x: visible;
}

.admin-group-list {
    display: grid;
    gap: 1rem;
}

.admin-group {
    border: 1px solid rgba(137, 61, 26, 0.12);
    border-radius: 20px;
    background: rgba(248, 241, 228, 0.36);
    overflow: hidden;
}

:root[data-theme="dark"] .admin-group {
    background: rgba(255, 181, 139, 0.03);
    border-color: rgba(255, 181, 139, 0.08);
}

.admin-group-done {
    border-color: rgba(47, 107, 63, 0.25);
}

.admin-group-warning {
    border-color: rgba(155, 45, 48, 0.25);
}

.admin-group-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    cursor: pointer;
    list-style: none;
}

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

.admin-group-summary::before {
    content: "▸";
    color: var(--accent-dark);
    font-weight: 700;
    margin-right: 0.75rem;
}

.admin-group[open] .admin-group-summary::before {
    transform: rotate(90deg);
}

.admin-group-main {
    display: grid;
    gap: 0.2rem;
    flex: 1;
}

.admin-group-state {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.group-delete-form {
    margin: 0;
}

.group-delete-button {
    padding: 0.55rem 0.95rem;
    border-radius: 999px;
    background: rgba(155, 45, 48, 0.14);
    color: var(--danger);
    border: 1px solid rgba(155, 45, 48, 0.28);
}

.group-delete-button:hover {
    background: rgba(155, 45, 48, 0.2);
}

:root[data-theme="dark"] .group-delete-button {
    background: rgba(255, 143, 143, 0.08);
    color: var(--danger);
    border-color: rgba(255, 143, 143, 0.22);
}

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

th,
td {
    text-align: left;
    padding: 0.7rem 0.7rem;
    border-bottom: 1px solid rgba(137, 61, 26, 0.12);
    vertical-align: top;
}

:root[data-theme="dark"] th,
:root[data-theme="dark"] td {
    border-bottom-color: rgba(255, 181, 139, 0.08);
}

th {
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.request-table {
    table-layout: fixed;
}

.request-table td,
.request-table th {
    font-size: 0.95rem;
}

.tight-col {
    width: 72px;
}

.table-check {
    justify-content: center;
}

.table-main {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.table-sub {
    display: grid;
    gap: 0.15rem;
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.table-stack {
    display: grid;
    gap: 0.45rem;
}

.table-actions {
    display: grid;
    gap: 0.5rem;
}

.attachment-links {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.file-upload-label {
    display: grid;
    gap: 0.3rem;
    min-width: 170px;
    font-size: 0.82rem;
    font-weight: 700;
}

.inline-note-label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.82rem;
    font-weight: 700;
}

.inline-note-label textarea {
    min-height: 68px;
    padding: 0.65rem 0.8rem;
    font-size: 0.88rem;
}

.file-upload-label input[type="file"] {
    padding: 0.45rem 0.5rem;
    font-size: 0.82rem;
}

:root[data-theme="dark"] .attachment-links a,
:root[data-theme="dark"] .attachment-links a:visited {
    color: var(--accent-dark);
}

.table-admin-form {
    min-width: 0;
    gap: 0.45rem;
}

.table-admin-form select {
    min-width: 0;
    padding: 0.65rem 0.8rem;
    font-size: 0.9rem;
}

.compact-ghost-button,
.table-admin-form .small-button {
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
}

.row-warning {
    background: rgba(155, 45, 48, 0.04);
}

.row-done {
    background: rgba(47, 107, 63, 0.04);
}

:root[data-theme="dark"] .row-warning {
    background: rgba(255, 143, 143, 0.05);
}

:root[data-theme="dark"] .row-done {
    background: rgba(142, 215, 169, 0.06);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
    font-weight: 700;
}

.status-pill.open {
    background: rgba(138, 104, 32, 0.14);
    color: var(--warning);
}

.status-pill.done {
    background: rgba(47, 107, 63, 0.14);
    color: var(--success);
}

:root[data-theme="dark"] .status-pill.open {
    background: rgba(240, 199, 104, 0.12);
}

:root[data-theme="dark"] .status-pill.done {
    background: rgba(142, 215, 169, 0.14);
}

.info-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: rgba(110, 95, 82, 0.12);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.de-link {
    text-decoration: none;
}

:root[data-theme="dark"] .info-badge {
    background: rgba(255, 255, 255, 0.06);
}

.badge-accent {
    background: rgba(185, 85, 40, 0.14);
    color: var(--accent-dark);
}

.badge-warning {
    background: rgba(155, 45, 48, 0.14);
    color: var(--danger);
}

:root[data-theme="dark"] .badge-accent {
    background: rgba(231, 125, 66, 0.16);
}

:root[data-theme="dark"] .badge-warning {
    background: rgba(255, 143, 143, 0.12);
}

.admin-inline-form,
.inline-row,
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.actions-cell {
    min-width: 260px;
}

.hint-cell {
    min-width: 170px;
}

.hint-details {
    width: 100%;
}

.hint-details summary {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    color: var(--accent-dark);
    font-weight: 700;
    list-style: none;
}

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

.hint-details summary::before {
    content: "▸";
    transition: transform 0.15s ease;
}

.hint-details[open] summary::before {
    transform: rotate(90deg);
}

.hint-content {
    margin-top: 0.65rem;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(137, 61, 26, 0.12);
    border-radius: 14px;
    background: rgba(248, 241, 228, 0.55);
    color: var(--text);
    white-space: normal;
    word-break: break-word;
}

:root[data-theme="dark"] .hint-content {
    background: rgba(255, 181, 139, 0.04);
    border-color: rgba(255, 181, 139, 0.1);
}

.action-group {
    display: grid;
    gap: 0.7rem;
}

.action-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid rgba(137, 61, 26, 0.12);
    border-radius: 16px;
    background: rgba(248, 241, 228, 0.55);
}

:root[data-theme="dark"] .action-form {
    background: rgba(255, 181, 139, 0.04);
    border-color: rgba(255, 181, 139, 0.1);
}

.action-form-inline {
    justify-content: flex-end;
}

.admin-inline-form {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
    flex-wrap: wrap;
}

.admin-inline-form select {
    min-width: 170px;
}

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

.checkbox-row.compact {
    font-weight: 500;
}

.info-list {
    padding-left: 1.2rem;
    margin-bottom: 0;
    color: var(--muted);
}

.theme-toggle {
    white-space: nowrap;
}

.empty-state {
    padding: 1.2rem;
    border-radius: 18px;
    background: rgba(248, 241, 228, 0.55);
    color: var(--muted);
}

:root[data-theme="dark"] .empty-state {
    background: rgba(255, 181, 139, 0.04);
}

@media (max-width: 900px) {
    .site-header,
    .hero-panel,
    .section-head,
    .header-nav,
    .admin-inline-form,
    .inline-row,
    .action-form {
        flex-direction: column;
        align-items: flex-start;
    }

    .page {
        padding: 1rem;
    }

    .header-center {
        width: 100%;
    }

    .grid-two {
        grid-template-columns: 1fr;
    }

    .request-entry-panel {
        max-width: none;
    }

    .compact-table-wrap {
        overflow-x: auto;
    }

    .actions-cell {
        min-width: 220px;
    }
}

@media (max-width: 700px) {
    .site-header {
        padding: 1rem;
    }

    .site-header h1 {
        font-size: 1.9rem;
    }

    .header-nav {
        width: 100%;
        gap: 0.6rem;
    }

    .refresh-button {
        width: 100%;
    }

    .header-nav a,
    .header-nav form,
    .header-nav .theme-toggle,
    .header-nav .ghost-button {
        width: 100%;
    }

    .header-nav .ghost-button,
    .header-nav a {
        text-align: center;
    }

    .hero-panel,
    .panel,
    .auth-card {
        border-radius: 18px;
    }

    .hero-panel,
    .panel {
        padding: 1rem;
    }

    .section-head-stack,
    .bulk-actions {
        align-items: stretch;
    }

    .bulk-actions {
        width: 100%;
    }

    .bulk-actions button {
        width: 100%;
    }

    .request-table,
    .request-table thead,
    .request-table tbody,
    .request-table tr,
    .request-table th,
    .request-table td {
        display: block;
        width: 100%;
    }

    .request-table thead {
        display: none;
    }

    .request-table tbody {
        display: grid;
        gap: 0.9rem;
    }

    .request-table tr {
        border: 1px solid rgba(137, 61, 26, 0.12);
        border-radius: 18px;
        background: var(--panel);
        padding: 0.2rem 0;
        box-shadow: var(--shadow);
    }

    .request-table td {
        border-bottom: 1px solid rgba(137, 61, 26, 0.08);
        padding: 0.8rem 0.9rem;
    }

    .request-table td:last-child {
        border-bottom: 0;
    }

    .request-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.35rem;
        color: var(--muted);
        font-size: 0.74rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }

    .tight-col {
        width: 100%;
    }

    .table-check {
        justify-content: flex-start;
    }

    .table-actions,
    .table-actions form,
    .table-admin-form,
    .table-admin-form select,
    .compact-ghost-button,
    .table-admin-form .small-button {
        width: 100%;
    }

    .table-admin-form {
        gap: 0.6rem;
    }

    .hint-cell {
        min-width: 0;
    }

    .hint-content {
        padding: 0.75rem 0.85rem;
    }
}
