:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --line: #d7dde4;
    --text: #1f2933;
    --muted: #667085;
    --primary: #1f6feb;
    --primary-dark: #1959bd;
    --danger: #c2410c;
    --warning-bg: #fff7ed;
    --warning-line: #fed7aa;
}

* {
    box-sizing: border-box;
}

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

body.modal-open {
    overflow: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
    padding: 12px 20px;
    background: #263238;
    color: #fff;
    border-bottom: 3px solid #1f6feb;
}

.topbar h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.topbar p {
    margin: 4px 0 0;
    color: #cfd8dc;
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.user-info {
    color: #f8fafc;
    font-weight: 700;
    white-space: nowrap;
}

.status {
    min-width: 96px;
    text-align: right;
    color: #e5eef7;
}

.workspace {
    padding: 14px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.panel-title h2 {
    margin: 0;
    font-size: 16px;
}

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

.search-box {
    display: grid;
    grid-template-columns: minmax(240px, 360px) 72px;
    gap: 8px;
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

th,
td {
    border-bottom: 1px solid #e5e9ef;
    padding: 9px 10px;
    text-align: left;
    vertical-align: top;
}

th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    color: #475467;
    font-size: 13px;
    white-space: nowrap;
}

td {
    color: #344054;
}

.row-actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.empty {
    height: 90px;
    color: var(--muted);
    text-align: center;
    vertical-align: middle;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.42);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    width: min(620px, 100%);
    max-height: calc(100vh - 36px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
}

.modal-header h2 {
    margin: 0;
    font-size: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px;
}

.form-message {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    margin: 0 14px 14px;
    padding: 10px;
    background: var(--warning-bg);
    border: 1px solid var(--warning-line);
    border-radius: 4px;
    color: #9a3412;
    font-weight: 700;
}

.form-message[hidden] {
    display: none;
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-weight: 700;
}

label span {
    color: var(--danger);
}

.wide {
    grid-column: 1 / -1;
}

input,
textarea {
    width: 100%;
    border: 1px solid #cbd5df;
    border-radius: 4px;
    padding: 9px 10px;
    color: var(--text);
    font: inherit;
    background: #fff;
}

input:read-only {
    background: #eef2f6;
    color: #475467;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 2px solid rgba(31, 111, 235, 0.12);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 14px 14px;
}

button {
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 8px 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.primary {
    background: var(--primary);
    color: #fff;
}

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

.secondary,
.topbar-logout {
    background: #eef2f6;
    border-color: #d5dce5;
    color: #263238;
}

.danger {
    background: #fff7ed;
    border-color: #fed7aa;
    color: var(--danger);
}

.icon-button {
    width: 36px;
    padding: 0;
    background: #eef2f6;
    border-color: #d5dce5;
    color: #263238;
    font-size: 20px;
    line-height: 1;
}

.user-menu {
    position: relative;
}

.user-menu-trigger {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #d5dce5;
    border-radius: 4px;
    padding: 8px 12px;
    background: #eef2f6;
    color: #263238;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    white-space: nowrap;
}

.user-menu-trigger::-webkit-details-marker {
    display: none;
}

.user-menu-trigger::after {
    content: "▼";
    font-size: 10px;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    min-width: 140px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
}

.user-menu-item {
    width: 100%;
    min-height: 38px;
    display: flex;
    align-items: center;
    border: 0;
    border-radius: 0;
    padding: 9px 12px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.user-menu-item:hover {
    background: #f3f6f9;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login-shell {
    width: 100%;
    max-width: 380px;
}

.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.login-title {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.login-title h1 {
    margin: 0;
    color: var(--text);
    font-size: 20px;
}

.login-title p {
    margin: 6px 0 0;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 12px;
    padding: 18px 20px 20px;
}

.login-error {
    padding: 10px;
    background: var(--warning-bg);
    border: 1px solid var(--warning-line);
    border-radius: 4px;
    color: #9a3412;
    font-weight: 700;
}

.login-submit {
    width: 100%;
    margin-top: 4px;
}

@media (max-width: 760px) {
    body {
        font-size: 15px;
    }

    .topbar {
        min-height: 48px;
        align-items: center;
        flex-direction: row;
        gap: 8px;
        padding: 8px 10px;
    }

    .topbar > div:first-child {
        min-width: 0;
    }

    .topbar h1 {
        font-size: 17px;
        line-height: 1.2;
        white-space: nowrap;
    }

    .topbar p,
    .status {
        display: none;
    }

    .topbar-right {
        align-items: center;
        flex-wrap: nowrap;
        justify-content: flex-end;
        gap: 8px;
        width: auto;
        min-width: 0;
        margin-left: auto;
    }

    .user-info {
        max-width: 34vw;
        overflow: hidden;
        font-size: 13px;
        text-overflow: ellipsis;
    }

    .topbar-logout {
        min-height: 34px;
        padding: 6px 10px;
        white-space: nowrap;
    }

    .user-menu-trigger {
        min-height: 34px;
        max-width: 38vw;
        overflow: hidden;
        padding: 6px 10px;
        font-size: 13px;
        text-overflow: ellipsis;
    }

    .user-menu-panel {
        min-width: 128px;
    }

    .workspace {
        padding: 10px;
    }

    .list-title {
        display: grid;
        grid-template-columns: auto minmax(120px, 1fr) auto;
        align-items: center;
        gap: 8px;
        min-height: 0;
        padding: 10px;
    }

    .list-title h2 {
        grid-column: 1;
        grid-row: 1;
        font-size: 16px;
        white-space: nowrap;
    }

    .list-title .toolbar {
        display: contents;
    }

    .list-title .search-box {
        grid-column: 2;
        grid-row: 1;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 40px;
        gap: 0;
        width: 100%;
        min-width: 0;
    }

    .search-box input {
        min-height: 40px;
        border-radius: 4px 0 0 4px;
    }

    .search-box button {
        min-height: 40px;
        width: 40px;
        border-left: 0;
        border-radius: 0 4px 4px 0;
        padding: 0;
        font-size: 0;
    }

    .search-box button::before {
        content: "\1F50D";
        font-size: 17px;
        line-height: 1;
    }

    .toolbar .button-link {
        display: none;
    }

    #newCustomerBtn {
        grid-column: 3;
        grid-row: 1;
        width: auto;
        min-height: 40px;
        padding: 8px 11px;
        white-space: nowrap;
        font-size: 0;
    }

    #newCustomerBtn::before {
        content: "+ 新增";
        font-size: 14px;
    }


    @media (max-width: 420px) {
        .list-title {
            grid-template-columns: minmax(0, 1fr) auto;
        }

        .list-title .search-box {
            grid-column: 1 / -1;
            grid-row: 2;
        }

        #newCustomerBtn {
            grid-column: 2;
        }
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 860px;
    }

    th,
    td {
        padding: 10px 9px;
    }

    .row-actions button {
        min-height: 40px;
        padding: 9px 12px;
    }

    .modal-backdrop {
        align-items: flex-start;
        padding: 8px;
    }

    .modal-panel {
        width: 100%;
        max-height: calc(100vh - 16px);
    }

    .form-grid,
    .form-message {
        grid-template-columns: 1fr;
    }

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

    input,
    textarea {
        min-height: 44px;
        padding: 10px 11px;
    }

    textarea {
        min-height: 88px;
    }

    .form-message {
        margin: 0 12px 12px;
    }

    .modal-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 0 12px 12px;
    }

    .modal-actions button,
    .form-message button,
    .icon-button {
        min-height: 44px;
    }

    .login-body {
        align-items: start;
        padding: 24px 12px;
    }

    .login-shell {
        max-width: none;
    }

    .login-title {
        padding: 16px;
    }

    .login-title h1 {
        font-size: 19px;
    }

    .login-form {
        gap: 14px;
        padding: 16px;
    }

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

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border: 1px solid #d5dce5;
    border-radius: 4px;
    padding: 8px 12px;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
}


.main-nav {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 20px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}

.main-nav-link,
.main-nav-group > summary {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    border-radius: 4px;
    padding: 7px 10px;
    color: #263238;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    list-style: none;
    white-space: nowrap;
}

.main-nav-link:hover,
.main-nav-group > summary:hover,
.main-nav-group[open] > summary {
    background: #eef2f6;
}

.main-nav-group {
    position: relative;
}

.main-nav-group > summary::-webkit-details-marker {
    display: none;
}

.main-nav-group > summary::after {
    content: "▼";
    margin-left: 6px;
    font-size: 10px;
    color: var(--muted);
}

.main-nav-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 35;
    min-width: 160px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
}

.main-nav-menu a,
.main-nav-menu button {
    width: 100%;
    min-height: 0;
    display: block;
    border: 0;
    border-radius: 0;
    padding: 10px 12px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.main-nav-form {
    margin: 0;
}

.main-nav-menu a:hover,
.main-nav-menu button:hover {
    background: #f3f6f9;
}

.dashboard-workspace {
    padding: 18px;
}

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

.dashboard-card {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.dashboard-card-header {
    padding: 14px;
    border-bottom: 1px solid var(--line);
}

.dashboard-card h2 {
    margin: 0;
    font-size: 18px;
}

.dashboard-card p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.dashboard-feature-list {
    display: grid;
}

.dashboard-feature {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 46px;
    padding: 11px 14px;
    border-bottom: 1px solid #e5e9ef;
    color: var(--text);
    text-decoration: none;
}

.dashboard-feature:last-child {
    border-bottom: 0;
}

.dashboard-feature:hover {
    background: #f8fafc;
}

.dashboard-feature strong {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 3px 8px;
    background: #e8f2ff;
    color: var(--primary-dark);
    font-size: 12px;
}

.dashboard-feature.disabled {
    color: var(--muted);
    cursor: default;
}

.dashboard-feature.disabled strong,
.coming-soon-panel h2 {
    background: #eef2f6;
    color: #475467;
}

.coming-soon-panel {
    max-width: 720px;
    padding: 24px;
}

.coming-soon-panel h2 {
    display: inline-flex;
    margin: 0 0 10px;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 13px;
}

.coming-soon-panel p {
    margin: 0 0 18px;
    color: var(--muted);
}

.public-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #f6f8fb 0%, #e9eef3 100%);
}

.public-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
}

.public-header h1,
.public-hero h2 {
    margin: 0;
}

.public-header p,
.public-hero p {
    margin: 6px 0 0;
    color: var(--muted);
}

.public-hero {
    min-height: calc(100vh - 82px);
    display: flex;
    align-items: center;
    padding: 48px 24px;
}

.public-hero section {
    max-width: 760px;
}

.public-hero h2 {
    color: var(--text);
    font-size: 36px;
    line-height: 1.25;
}

.public-hero p {
    max-width: 580px;
    font-size: 16px;
    line-height: 1.7;
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .main-nav {
        min-height: 40px;
        gap: 4px;
        overflow-x: auto;
        padding: 5px 10px;
        -webkit-overflow-scrolling: touch;
    }

    .main-nav-link,
    .main-nav-group > summary {
        min-height: 30px;
        padding: 6px 9px;
        font-size: 13px;
    }

    .main-nav-menu {
        position: fixed;
        top: 90px;
        left: 10px;
        right: 10px;
        min-width: 0;
    }

    .dashboard-workspace {
        padding: 10px;
    }

    .dashboard-card-header {
        padding: 12px;
    }

    .dashboard-card h2 {
        font-size: 17px;
    }

    .dashboard-feature {
        min-height: 44px;
        padding: 10px 12px;
    }

    .coming-soon-panel {
        padding: 18px;
    }

    .public-header {
        padding: 14px 12px;
    }

    .public-header h1 {
        font-size: 20px;
    }

    .public-header p {
        display: none;
    }

    .public-hero {
        min-height: calc(100vh - 65px);
        align-items: flex-start;
        padding: 42px 16px;
    }

    .public-hero h2 {
        font-size: 28px;
    }
}


.dashboard-heading {
    margin-bottom: 14px;
}

.dashboard-heading h2 {
    margin: 0;
    font-size: 20px;
}

.dashboard-heading p {
    margin: 6px 0 0;
    color: var(--muted);
}

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

.dashboard-entry-card {
    min-height: 168px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 16px;
    color: var(--text);
    text-decoration: none;
}

.dashboard-entry-card:hover {
    border-color: #b8c4d2;
    background: #f8fafc;
}

.dashboard-entry-status {
    border-radius: 999px;
    padding: 3px 8px;
    background: #eef2f6;
    color: #475467;
    font-size: 12px;
    font-weight: 700;
}

.dashboard-entry-card h3 {
    margin: 18px 0 8px;
    font-size: 18px;
}

.dashboard-entry-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

@media (max-width: 980px) {
    .dashboard-entry-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .dashboard-entry-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-entry-card {
        min-height: 138px;
    }
}


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

.dashboard-section-card {
    min-width: 0;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.dashboard-section-title {
    padding: 14px;
    border-bottom: 1px solid var(--line);
}

.dashboard-section-title h3 {
    margin: 0;
    font-size: 18px;
}

.dashboard-section-list {
    display: grid;
}

.dashboard-section-action {
    width: 100%;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 0;
    border-bottom: 1px solid #e5e9ef;
    border-radius: 0;
    padding: 11px 14px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.dashboard-section-action:hover {
    background: #f8fafc;
    color: var(--primary-dark);
}

.dashboard-section-action strong {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 3px 8px;
    background: #e8f2ff;
    color: var(--primary-dark);
    font-size: 12px;
}

.dashboard-section-form {
    margin: 0;
}

.dashboard-section-form:last-child .dashboard-section-action,
.dashboard-section-list > .dashboard-section-action:last-child {
    border-bottom: 0;
}

@media (max-width: 1100px) {
    .dashboard-section-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .dashboard-section-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-section-title {
        padding: 12px;
    }

    .dashboard-section-action {
        min-height: 44px;
        padding: 10px 12px;
    }
}
