:root {
    --bg: #f6f8fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #657188;
    --line: #dfe5ef;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --danger: #dc2626;
    --shadow: 0 12px 30px rgba(23, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Arial, "Microsoft YaHei", sans-serif;
}

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

button,
a {
    cursor: pointer;
}

.shell,
.admin-shell,
.doc-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.hero {
    min-height: 72vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 48px;
    align-items: center;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--brand);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 48px;
    line-height: 1.1;
}

.lead {
    max-width: 620px;
    margin: 20px 0 0;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.8;
}

.hero-actions {
    display: flex;
    gap: 12px;
    margin-top: 30px;
}

.primary-link,
.secondary-link,
button {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 16px;
    text-decoration: none;
    background: var(--panel);
    color: var(--text);
}

.primary-link,
.primary-button {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.primary-link:hover,
.primary-button:hover {
    background: var(--brand-dark);
}

.status-panel,
.service-grid article,
.table-wrap,
.modal-content,
.doc-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.status-panel {
    padding: 24px;
}

.status-panel div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.status-panel div:last-child {
    border-bottom: 0;
}

.status-panel span {
    color: var(--muted);
}

.service-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 48px;
}

.service-grid article {
    padding: 20px;
}

.service-grid h2,
.doc-card h2,
.modal-content h2 {
    margin: 0 0 10px;
    font-size: 20px;
}

.service-grid p,
.doc-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.admin-shell {
    padding: 24px 0;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: end;
    margin-bottom: 18px;
}

.admin-header h1 {
    font-size: 30px;
}

.doc-admin-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    background: rgba(246, 248, 251, 0.94);
    backdrop-filter: blur(10px);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

input,
textarea,
select {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

.toolbar input {
    width: 220px;
}

.table-wrap {
    max-width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1120px;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--line);
    padding: 12px;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    background: #f1f5fb;
    color: #3b465a;
    font-size: 13px;
}

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

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px 0;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10;
    overflow: auto;
    background: rgba(17, 24, 39, 0.55);
    padding: 24px;
}

.modal-content {
    position: relative;
    width: min(560px, 100%);
    margin: 20px auto;
    padding: 24px;
}

.wide-modal {
    width: min(920px, 100%);
}

.left-toolbar {
    justify-content: flex-start;
    margin: 10px 0;
}

.compact-table {
    min-width: 520px;
}

.doc-admin-shell {
    width: min(1320px, calc(100% - 32px));
    padding-bottom: 40px;
    --brand: #3498db;
    --brand-dark: #2b80ba;
}

.doc-admin-grid {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.doc-admin-list,
.doc-editor,
.import-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.doc-admin-list {
    position: sticky;
    top: 104px;
    max-height: calc(100vh - 128px);
    overflow: auto;
    padding: 16px;
}

#doc-list {
    display: grid;
    gap: 8px;
}

.doc-list-item {
    width: 100%;
    display: grid;
    gap: 4px;
    padding: 12px;
    text-align: left;
    background: #f8fafc;
}

.doc-list-item strong {
    color: var(--text);
}

.doc-list-item span {
    color: var(--muted);
    font-size: 13px;
}

.doc-editor {
    padding: 18px;
}

.doc-editor form label {
    display: grid;
    gap: 6px;
}

.editor-panel {
    display: grid;
    gap: 10px;
    margin: 12px 0;
}

.flat-table {
    box-shadow: none;
}

.floating-actions {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 30;
    display: flex;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 80;
    max-width: min(360px, calc(100vw - 32px));
    transform: translateY(12px);
    opacity: 0;
    pointer-events: none;
    border-radius: 8px;
    background: #0f172a;
    color: #fff;
    padding: 11px 14px;
    box-shadow: var(--shadow);
    transition: 0.18s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    background: #991b1b;
}

.choice-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 70;
    transform: translate(-50%, -50%);
    width: min(420px, 100%);
    margin: 0;
}

#doc-choice-modal {
    position: fixed;
    inset: auto;
    z-index: 70;
    overflow: visible;
    background: transparent;
    padding: 0;
    pointer-events: none;
}

#doc-choice-modal .modal-content {
    pointer-events: auto;
}

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

.import-panel {
    margin-top: 18px;
    padding: 18px;
}

.import-panel h2 {
    margin: 0 0 8px;
}

.import-panel p {
    margin: 0 0 12px;
    color: var(--muted);
}

.list-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.close {
    position: absolute;
    top: 16px;
    right: 16px;
    border-color: transparent;
    background: #eef2f7;
}

form {
    display: grid;
    gap: 8px;
}

form label {
    margin-top: 8px;
    color: #3b465a;
    font-size: 14px;
}

.doc-shell {
    padding: 32px 0;
}

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

.doc-grid {
    display: grid;
    gap: 16px;
}

.two-col {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.doc-card {
    padding: 20px;
}

.user-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 18px 0;
}

.user-nav a,
.user-nav button {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 13px;
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
}

.user-nav a.active {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.user-page {
    background: #eef3f8;
}

.user-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 24px 18px;
    border-right: 1px solid var(--line);
    background: #ffffff;
}

.sidebar-brand {
    padding: 8px 10px 18px;
    border-bottom: 1px solid var(--line);
    color: var(--text);
    font-size: 18px;
    font-weight: 800;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.sidebar-nav a,
.sidebar-logout {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 11px 12px;
    color: #334155;
    background: transparent;
    text-align: left;
    text-decoration: none;
}

.sidebar-nav a:hover,
.sidebar-logout:hover {
    background: #f1f5f9;
}

.sidebar-nav a.active {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--brand);
    font-weight: 700;
}

.sidebar-logout {
    margin-top: auto;
    border-color: var(--line);
    text-align: center;
}

.user-main {
    width: min(1220px, calc(100% - 40px));
    margin: 0 auto;
    padding: 28px 0 40px;
}

.dashboard-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.action-bar strong {
    display: block;
    margin-bottom: 4px;
    font-size: 18px;
}

.action-bar span,
.status-note,
.form-message {
    color: var(--muted);
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-title-row h2,
.section-title-row h3 {
    margin: 0;
}

.rate-panel.show-monthly tr.monthly-rate td,
.rate-editor.show-monthly .monthly-rate {
    background: #fff7ed;
    box-shadow: inset 3px 0 0 #f59e0b;
}

.rate-category-row td,
.rate-category-label {
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
}

.rate-category-label {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
}

button.active {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #92400e;
}

.danger-button {
    border-color: #fecaca;
    background: #fff1f2;
    color: var(--danger);
}

.danger-button:hover {
    background: #ffe4e6;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-width: 48px;
    justify-content: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 700;
}

.status-pill.enabled {
    background: #dcfce7;
    color: #166534;
}

.status-pill.disabled {
    background: #fee2e2;
    color: #991b1b;
}

.inline-code {
    display: inline-block;
    margin: 0;
    padding: 4px 7px;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    white-space: nowrap;
}

.empty-cell {
    padding: 26px 12px !important;
    color: var(--muted);
    text-align: center !important;
}

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

.form-grid label {
    grid-column: auto;
}

.form-grid label + input,
.form-grid label + select {
    width: 100%;
}

.modal-rate-title {
    margin-top: 18px;
}

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

.rate-editor-row {
    display: grid;
    grid-template-columns: minmax(92px, 1fr) minmax(0, 150px);
    gap: 10px;
    align-items: center;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.rate-editor-row input {
    min-height: 36px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.action-bar .pagination {
    padding: 0;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.metric-grid.dashboard-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-grid article {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    box-shadow: var(--shadow);
    padding: 22px;
}

.metric-grid span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 12px;
}

.metric-grid strong {
    display: block;
    color: var(--text);
    font-size: 30px;
    line-height: 1.1;
}

.inline-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

code {
    display: block;
    margin-top: 12px;
    padding: 14px;
    overflow-x: auto;
    border-radius: 8px;
    background: #111827;
    color: #f8fafc;
    white-space: pre-wrap;
}

@media (max-width: 1024px) {
    .admin-shell,
    .doc-admin-shell {
        width: min(100% - 24px, 1180px);
    }

    .hero,
    .service-grid,
    .metric-grid,
    .two-col,
    .dashboard-metrics,
    .form-grid,
    .doc-admin-grid,
    .rate-editor {
        grid-template-columns: 1fr;
    }

    .doc-admin-list {
        position: static;
        max-height: 280px;
        overflow: auto;
    }

    .floating-actions {
        left: 12px;
        right: 12px;
        bottom: 12px;
        justify-content: stretch;
    }

    .floating-actions button {
        flex: 1;
    }

    h1 {
        font-size: 36px;
    }

    .hero {
        min-height: auto;
        padding: 48px 0 28px;
    }

    .admin-header,
    .doc-header {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar {
        justify-content: stretch;
    }

    .toolbar input,
    .toolbar button,
    .toolbar a {
        width: 100%;
        text-align: center;
    }

    .user-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .sidebar-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sidebar-logout {
        margin-top: 0;
    }

    .user-main {
        width: min(100% - 24px, 1220px);
        padding-top: 20px;
    }

    .action-bar,
    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 720px) {
    .admin-shell {
        padding: 12px 0 28px;
    }

    .admin-header h1 {
        font-size: 24px;
    }

    .doc-admin-topbar {
        position: static;
        padding-top: 0;
    }

    .doc-editor,
    .doc-admin-list,
    .import-panel,
    .modal-content {
        padding: 14px;
    }

    .data-table {
        min-width: 760px;
    }

    .table-wrap {
        margin-inline: -2px;
    }

    .modal {
        padding: 12px;
    }

    .modal-content {
        margin: 12px auto;
    }

    .toast {
        left: 12px;
        right: 12px;
        bottom: 14px;
        max-width: none;
        text-align: center;
    }
}
