:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --line: #d9e0ea;
    --text: #1f2937;
    --muted: #667085;
    --primary: #1677ff;
    --primary-dark: #0958d9;
    --danger: #d92d20;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
}

button:hover {
    background: var(--primary-dark);
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    outline: none;
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
}

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

.login-page {
    display: grid;
    place-items: center;
    background: #eef3fb;
}

.login-shell {
    width: min(420px, calc(100vw - 32px));
}

.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 18px 50px rgba(31, 41, 55, .1);
}

.login-panel h1 {
    margin: 0 0 24px;
    font-size: 26px;
}

.form-stack,
.dialog-form {
    display: grid;
    gap: 16px;
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 14px;
}

.form-message {
    min-height: 20px;
    margin: 0;
    color: var(--danger);
}

.app-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #14213d;
    color: #fff;
    padding: 20px 14px;
}

.brand-title {
    font-size: 19px;
    font-weight: 700;
    margin-bottom: 24px;
}

.menu {
    display: grid;
    gap: 8px;
}

.menu-item {
    display: block;
    width: 100%;
    border: 0;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    text-decoration: none;
    text-align: left;
}

.menu-item.active,
.menu-item:hover {
    background: #1677ff;
}

.workspace {
    min-width: 0;
    padding: 24px;
}

.view-panel {
    display: none;
}

.view-panel.active {
    display: block;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 20px;
}

.topbar h1 {
    margin: 0 0 6px;
    font-size: 24px;
}

.topbar p {
    margin: 0;
    color: var(--muted);
}

.user-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar,
.table-section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.toolbar {
    display: flex;
    align-items: end;
    gap: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.filter-field {
    width: 240px;
}

.checkbox-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    color: var(--text);
    white-space: nowrap;
}

.checkbox-field input {
    width: 16px;
    height: 16px;
    padding: 0;
}

.checkbox-field span {
    margin: 0;
    font-size: 14px;
    color: var(--text);
}

.primary-button {
    margin-left: auto;
}

.ghost-button {
    background: #fff;
    color: var(--text);
    border-color: var(--line);
}

.ghost-button:hover {
    background: #f8fafc;
}

.table-section {
    overflow-x: auto;
    overflow-y: hidden;
}

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

.task-form,
.task-list-toolbar,
.detail-section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.task-form {
    display: grid;
    gap: 14px;
    padding: 16px;
}

.task-form h2,
.detail-section h2 {
    margin: 0;
    font-size: 18px;
}

.task-form .primary-button {
    width: 100%;
    margin-left: 0;
}

.task-list-section {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.task-list-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.detail-section {
    display: grid;
    gap: 12px;
    padding: 16px;
}

.task-detail {
    min-height: 220px;
    max-height: 420px;
    overflow: auto;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    padding: 12px;
    color: var(--text);
    font-family: "Consolas", "SFMono-Regular", monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.selected-row td {
    background: #f0f7ff;
}

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
    text-align: left;
    vertical-align: middle;
    font-size: 14px;
}

th {
    background: #f8fafc;
    color: #344054;
    font-weight: 600;
}

.action-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-group button,
.action-group a {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    padding: 5px 9px;
    text-decoration: none;
    font-size: 13px;
}

.action-group button:hover,
.action-group a:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.action-group button:disabled {
    border-color: var(--line);
    background: #f2f4f7;
    color: #98a2b3;
}

.action-group .danger-action {
    border-color: #fecdca;
    color: var(--danger);
}

.action-group .danger-action:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.record-stats {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 13px;
    min-width: 120px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 24px;
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.ready {
    background: #ecfdf3;
    color: #067647;
}

.status-badge.pending {
    background: #fff7ed;
    color: #b54708;
}

.status-badge.failed {
    background: #fef3f2;
    color: #b42318;
}

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

.place-order-cell,
.place-order-meta {
    display: grid;
    gap: 4px;
    min-width: 150px;
}

.response-summary {
    display: block;
    max-width: 240px;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pager {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 14px;
}

dialog {
    width: min(520px, calc(100vw - 32px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 20px 70px rgba(15, 23, 42, .22);
}

dialog::backdrop {
    background: rgba(15, 23, 42, .36);
}

.wide-dialog {
    width: 80vw;
    max-width: calc(100vw - 32px);
}

.dialog-form {
    padding: 20px;
}

.dialog-form header,
.dialog-form footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.dialog-form h2 {
    margin: 0;
    font-size: 20px;
}

.dialog-form footer {
    justify-content: flex-end;
}

.icon-close {
    width: 32px;
    height: 32px;
    padding: 0;
    border-color: var(--line);
    background: #fff;
    color: var(--text);
    font-size: 22px;
    line-height: 1;
}

.file-picker {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 38px;
}

.file-picker input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.file-picker button {
    width: auto;
}

.file-picker span {
    overflow: hidden;
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-table {
    max-height: 68vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.preview-grid {
    width: max-content;
    min-width: 100%;
    table-layout: fixed;
}

.preview-grid th,
.preview-grid td {
    min-width: 150px;
    max-width: 260px;
    white-space: normal;
    word-break: break-word;
}

.preview-grid th:first-child,
.preview-grid td:first-child {
    min-width: 92px;
    max-width: 92px;
}

.preview-grid th.sticky-status,
.preview-grid td.sticky-status {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    box-shadow: 1px 0 0 var(--line);
}

.preview-grid th.sticky-status {
    z-index: 3;
    background: #f8fafc;
}

.preview-grid th.wide-text,
.preview-grid td.wide-text {
    min-width: 280px;
    max-width: 420px;
}

.preview-grid th.extra-wide-text,
.preview-grid td.extra-wide-text {
    min-width: 360px;
    max-width: 560px;
}

.preview-hint {
    color: var(--muted);
    font-size: 13px;
}

.inline-edit {
    min-width: 120px;
    padding: 6px 8px;
}

.empty {
    padding: 28px;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 800px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        padding: 14px;
    }

    .toolbar,
    .topbar,
    .appointment-layout,
    .task-list-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .appointment-layout {
        display: flex;
    }

    .filter-field,
    .primary-button {
        width: 100%;
        margin-left: 0;
    }
}
