* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f6f7f9;
    color: #1f2937;
    font-family: "Inter", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

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

.login-card {
    width: min(420px, 100%);
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    padding: 28px;
    box-shadow: 0 12px 36px rgba(15, 23, 42, .08);
}

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

.sidebar {
    background: #111827;
    color: #f9fafb;
    padding: 22px 18px;
}

.brand {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 22px;
}

.nav-link {
    display: block;
    border-radius: 8px;
    color: #d1d5db;
    padding: 10px 12px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.nav-link:hover,
.nav-link.active {
    background: #1f2937;
    color: #fff;
}

.nav-form {
    margin: 0;
}

.nav-button {
    width: 100%;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

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

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

.page-title {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
}

.muted {
    color: #6b7280;
    font-size: 13px;
}

.grid {
    display: grid;
    gap: 14px;
}

.stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 16px;
}

.card {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    padding: 16px;
}

.stat-value {
    font-size: 26px;
    font-weight: 850;
    margin-top: 4px;
}

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

.field {
    display: grid;
    gap: 6px;
}

.label {
    color: #4b5563;
    font-size: 12px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    background: #fff;
    padding: 8px 10px;
    color: #111827;
    font: inherit;
}

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

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid #0f766e;
    border-radius: 7px;
    background: #0f766e;
    color: #fff;
    padding: 8px 13px;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button.secondary {
    border-color: #d1d5db;
    background: #fff;
    color: #374151;
}

.button.danger {
    border-color: #dc2626;
    background: #dc2626;
    color: #fff;
}

.tool-panel summary {
    width: fit-content;
    list-style: none;
}

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

.tool-panel-body {
    margin-top: 16px;
}

.settings-license-module-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.license-anomaly {
    display: inline-flex;
    margin-bottom: 4px;
}

.license-anomaly-summary {
    max-width: 260px;
    color: #991b1b;
    font-size: 12px;
    line-height: 1.45;
}

.client-inline-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr) auto;
    gap: 12px;
    align-items: end;
}

.compact-client-card {
    padding: 10px 12px;
}

.compact-client-form {
    grid-template-columns: 180px 230px auto;
    gap: 8px;
}

.compact-client-form .field,
.license-adjust-form .field {
    gap: 3px;
}

.compact-client-form .label,
.license-adjust-form .label {
    font-size: 11px;
}

.compact-client-form input,
.license-adjust-form input,
.license-adjust-form select {
    min-height: 30px;
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 13px;
}

.compact-client-form .button,
.license-adjust-form .button {
    min-height: 30px;
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 12px;
}

.license-adjust-card {
    padding: 12px;
}

.license-adjust-card h2 {
    margin: 0 0 8px;
    font-size: 15px;
    line-height: 1.25;
}

.license-adjust-form {
    display: grid;
    grid-template-columns: minmax(150px, 1.3fr) minmax(180px, 1.5fr) 92px 82px 124px 124px 82px 82px 104px auto;
    gap: 8px;
    align-items: end;
}

.license-adjust-actions {
    display: flex;
    gap: 6px;
    align-items: end;
    white-space: nowrap;
}

.history-actions,
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.pagination {
    justify-content: space-between;
    margin-top: 12px;
}

.history-table {
    min-width: 1120px;
}

.event-id {
    max-width: 360px;
    overflow-wrap: anywhere;
}

.delta-positive {
    color: #047857;
    font-weight: 850;
}

.delta-negative {
    color: #b91c1c;
    font-weight: 850;
}

.generator-grid {
    display: grid;
    grid-template-columns: 140px minmax(250px, 1.4fr) minmax(180px, 1fr) 160px 160px;
    gap: 12px;
    align-items: end;
}

.generator-grid .site-field {
    min-width: 0;
}

.generator-submit {
    align-self: end;
    white-space: nowrap;
}

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

.span-2 {
    grid-column: span 2;
}

.span-4 {
    grid-column: span 4;
}

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

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

th,
td {
    border-bottom: 1px solid #eef0f3;
    padding: 11px 10px;
    text-align: left;
    vertical-align: middle;
    font-size: 13px;
}

th {
    color: #6b7280;
    font-size: 12px;
    font-weight: 850;
    background: #f9fafb;
}

.mono {
    font-family: "JetBrains Mono", "Consolas", monospace;
}

.badge {
    display: inline-flex;
    border-radius: 999px;
    padding: 4px 8px;
    background: #ecfdf5;
    color: #047857;
    font-size: 12px;
    font-weight: 800;
}

.badge.warn {
    background: #fffbeb;
    color: #b45309;
}

.badge.danger {
    background: #fef2f2;
    color: #b91c1c;
}

.alert {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.success {
    border: 1px solid #99f6e4;
    background: #f0fdfa;
    color: #115e59;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

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

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 18px;
    background: rgba(15, 23, 42, .38);
    overflow-y: auto;
}

.modal-card {
    width: min(760px, calc(100vw - 36px));
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 22px 60px rgba(15, 23, 42, .24);
}

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

.modal-head h2 {
    margin: 0;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    color: #374151;
    text-decoration: none;
    background: #f3f4f6;
    font-size: 22px;
    line-height: 1;
}

.modal-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

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

.modal-danger-form {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #fee2e2;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: static;
    }
    .stats,
    .form-grid,
    .client-inline-form,
    .license-adjust-form,
    .generator-grid,
    .two-col {
        grid-template-columns: 1fr;
    }
    .span-2,
    .span-4 {
        grid-column: auto;
    }
    .topbar-actions,
    .modal-form-grid {
        grid-template-columns: 1fr;
    }
    .topbar-actions {
        justify-content: flex-start;
    }
}

.billing-page .card {
    padding: 12px;
}

.billing-page .compact-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.billing-page .compact-actions form,
.billing-page .inline-action-form {
    margin: 0;
}

.billing-page h2 {
    margin: 0 0 10px;
    font-size: 16px;
}

.billing-page .billing-form-grid,
.billing-page .compact-form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 10px;
    align-items: end;
}

.billing-page .billing-wide {
    grid-column: span 2;
}

.billing-page .compact-number {
    max-width: 150px;
}

.billing-page .table-wrap table {
    min-width: 760px;
}

.billing-page th,
.billing-page td {
    padding: 7px 8px;
    font-size: 12px;
    vertical-align: top;
}

.billing-page .muted {
    font-size: 12px;
}

.billing-page .button,
.billing-page input,
.billing-page select,
.billing-page textarea {
    min-height: 32px;
    font-size: 12px;
    padding: 6px 9px;
}

.billing-page textarea {
    min-height: 70px;
}

.billing-page .mini-button {
    min-height: 28px;
    padding: 4px 8px;
}

.billing-page .billing-order {
    padding: 10px 0;
    border-bottom: 1px solid #eef0f3;
}

.billing-page .billing-order-head,
.support-ticket-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.billing-page .billing-order h3 {
    margin: 4px 0;
    font-size: 14px;
}

.billing-page .billing-order-actions,
.support-ticket-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: flex-start;
}

.billing-page .billing-order-actions form,
.support-ticket-actions form {
    margin: 0;
}

.billing-page .image-source-field {
    gap: 7px;
}

@media (max-width: 980px) {
    .billing-page .billing-form-grid,
    .billing-page .compact-form-grid {
        grid-template-columns: 1fr;
    }
    .billing-page .billing-wide {
        grid-column: auto;
    }
    .billing-page .billing-order-actions,
    .support-ticket-actions {
        justify-content: flex-start;
    }
    .billing-page .billing-order-head,
    .support-ticket-head {
        display: grid;
    }
}
