:root {
    --bg: #f1f5f8;
    --sidebar: #23313f;
    --sidebar-strong: #17222e;
    --text: #25303d;
    --muted: #687789;
    --line: #dce3ea;
    --panel: #ffffff;
    --primary: #2082c7;
    --primary-dark: #17679f;
    --success: #12a66a;
    --danger: #d94b45;
    --warning: #f2a526;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Arial, "Microsoft JhengHei", "PingFang TC", sans-serif;
    line-height: 1.55;
}

a {
    color: var(--primary);
}

.icon {
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 auto;
}

.admin-body {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.admin-sidebar {
    min-height: 100vh;
    background: var(--sidebar);
    color: #fff;
    padding: 22px 16px;
}

.admin-brand {
    padding: 10px 12px 22px;
    font-size: 1.2rem;
    font-weight: 800;
}

.admin-nav {
    display: grid;
    gap: 6px;
}

.admin-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #dce7ef;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
}

.admin-nav a:hover {
    background: var(--sidebar-strong);
    color: #fff;
}

.admin-main {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 52px;
}

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

.admin-topbar h1 {
    margin: 0;
    font-size: 2rem;
    line-height: 1.2;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
}

.admin-user {
    padding: 8px 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
}

.panel,
.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(31, 45, 61, 0.06);
}

.panel {
    padding: 22px;
    margin-bottom: 20px;
}

.panel.narrow {
    max-width: 720px;
}

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

.panel-head h2 {
    margin: 0;
    font-size: 1.2rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    padding: 18px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 0.95rem;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 2rem;
    line-height: 1;
}

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

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

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: #4a596a;
    background: #f6f8fa;
    font-size: 0.92rem;
}

td small,
.muted {
    color: var(--muted);
}

.long-text {
    max-width: 360px;
    overflow-wrap: anywhere;
}

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.inline-form {
    display: inline;
    margin: 0;
}

.inline-form button {
    border: 0;
    padding: 0;
    color: var(--primary);
    background: transparent;
    font: inherit;
    cursor: pointer;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.85rem;
    font-weight: 700;
}

.badge.active {
    color: #0b7048;
    background: #dff8ed;
}

.badge.inactive {
    color: #8f312e;
    background: #fde6e4;
}

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

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

.full-span {
    grid-column: 1 / -1;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: #405065;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid #cfd8e2;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    background: #fff;
    font: inherit;
}

textarea {
    resize: vertical;
}

input[type="file"] {
    padding: 9px;
}

label small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 6px;
}

.button,
button.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px;
    padding: 9px 15px;
    border: 1px solid var(--line);
    text-decoration: none;
    font-weight: 800;
    cursor: pointer;
    font: inherit;
}

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

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

.button.secondary {
    color: var(--text);
    background: #fff;
}

.button.small {
    min-height: 36px;
    padding: 7px 12px;
    font-size: 0.92rem;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
}

.alert-success {
    color: #0b7048;
    background: #e7fbf1;
    border-color: #c4f0dc;
}

.alert-error {
    color: #8f312e;
    background: #fdebea;
    border-color: #f6c7c4;
}

.filter-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.filter-form select {
    min-width: 180px;
}

.detail-list {
    display: grid;
    gap: 12px;
}

.detail-list div {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 12px;
}

.detail-list span {
    color: var(--muted);
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #edf3f7;
}

.login-panel {
    width: min(100%, 420px);
}

.login-card {
    padding: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 44px rgba(32, 52, 72, 0.12);
}

.login-card h1 {
    margin: 0 0 20px;
    font-size: 1.9rem;
}

.template-picker {
    margin: 0;
    padding: 0;
    border: 0;
}

.template-picker legend {
    margin-bottom: 8px;
    color: var(--text);
    font-weight: 700;
}

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

.template-choice {
    position: relative;
    display: grid;
    gap: 7px;
    cursor: pointer;
}

.template-choice input {
    position: absolute;
    opacity: 0;
}

.template-choice strong {
    font-size: 0.82rem;
}

.template-preview {
    position: relative;
    display: block;
    min-height: 92px;
    overflow: hidden;
    border: 2px solid #dbe2e8;
    border-radius: 6px;
    background: #f7f8fa;
}

.template-preview::before,
.template-preview i,
.template-preview b,
.template-preview em {
    position: absolute;
    display: block;
    content: "";
}

.template-preview::before {
    inset: 0 0 auto;
    height: 32px;
    background: #94bfd7;
}

.template-preview i {
    top: 20px;
    left: 12px;
    width: 28px;
    height: 28px;
    border: 3px solid #fff;
    border-radius: 50%;
    background: #467f9e;
}

.template-preview b,
.template-preview em {
    left: 12px;
    right: 12px;
    height: 4px;
    background: #7d8995;
}

.template-preview b { top: 59px; }
.template-preview em { top: 70px; opacity: 0.55; }

.template-preview-minimal { background: #fff; }
.template-preview-minimal::before { height: 18px; background: #e1e5e7; }
.template-preview-minimal i { top: 12px; left: calc(50% - 14px); border-color: #fff; background: #73869a; }
.template-preview-minimal b,
.template-preview-minimal em { left: 20px; right: 20px; }

.template-preview-brand { background: #f0f4f7; }
.template-preview-brand::before { height: 42px; background: #2082c7; }
.template-preview-brand i { top: 29px; background: #2082c7; }

.template-preview-midnight { background: #172534; }
.template-preview-midnight::before { height: 36px; background: #30485e; }
.template-preview-midnight i { background: #2b86c9; }
.template-preview-midnight b,
.template-preview-midnight em { background: #d4e0e8; }

.template-choice input:checked + .template-preview {
    border-color: #2082c7;
    box-shadow: 0 0 0 3px rgba(32, 130, 199, 0.16);
}

.activity-chart {
    min-height: 184px;
    display: flex;
    align-items: end;
    gap: 10px;
    padding: 18px 4px 0;
    border-bottom: 1px solid var(--line);
}

.activity-bar-item {
    min-width: 38px;
    flex: 1 1 0;
    display: grid;
    justify-items: center;
    gap: 5px;
}

.activity-total,
.activity-bar-item small {
    color: var(--muted);
    font-size: 0.73rem;
}

.activity-bar {
    width: min(28px, 100%);
    display: flex;
    align-items: flex-start;
    overflow: hidden;
    border-radius: 4px 4px 0 0;
    background: #e5ad3d;
}

.activity-bar i {
    width: 100%;
    display: block;
    background: #2082c7;
}

.chart-key {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.chart-key span {
    width: 10px;
    height: 10px;
    display: inline-block;
    margin: 0 4px 0 14px;
    border-radius: 2px;
}

.chart-key .chart-key-view { margin-left: 0; background: #2082c7; }
.chart-key .chart-key-action { background: #e5ad3d; }

.panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.analytics-filter-panel {
    padding: 18px 22px;
}

.analytics-filters {
    display: grid;
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    gap: 12px;
    align-items: end;
}

.analytics-filters label span {
    margin-bottom: 5px;
    font-size: 0.82rem;
}

.analytics-checkbox {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 2px;
}

.analytics-checkbox input {
    width: 18px;
    min-height: 18px;
    height: 18px;
    margin: 0;
}

.analytics-checkbox span {
    display: inline;
    margin: 0 !important;
}

.analytics-filter-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.analytics-stat-grid .stat-card {
    min-width: 0;
}

.metric-change {
    display: block;
    margin-top: 9px;
    color: var(--muted);
    font-size: 0.75rem;
}

.metric-change.positive {
    color: var(--success);
}

.metric-change.negative {
    color: var(--danger);
}

.analytics-period {
    margin: 4px 0 0;
    font-size: 0.82rem;
}

.trend-chart-wrap {
    overflow-x: auto;
    padding: 8px 0 4px;
}

.trend-chart {
    min-width: max(100%, 760px);
    min-height: 180px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(34px, 1fr);
    align-items: end;
    gap: 5px;
    border-bottom: 1px solid var(--line);
}

.trend-day {
    min-width: 0;
    display: grid;
    justify-items: center;
    gap: 5px;
}

.trend-values {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.trend-bars {
    height: 132px;
    display: flex;
    align-items: end;
    justify-content: center;
    gap: 2px;
}

.trend-bars i {
    width: 7px;
    min-height: 2px;
    display: block;
    border-radius: 3px 3px 0 0;
}

.trend-view {
    background: #2082c7;
}

.trend-visitor {
    background: #12a66a;
}

.trend-action {
    background: #e5ad3d;
}

.trend-day small {
    color: var(--muted);
    font-size: 0.68rem;
    white-space: nowrap;
}

.analytics-chart-key .chart-key-visitor {
    background: #12a66a;
}

.analytics-breakdown-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.analytics-breakdown-grid table {
    min-width: 420px;
}

.analytics-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 0.85rem;
}

.analytics-note {
    margin: 0 0 20px;
    font-size: 0.82rem;
}

@media (max-width: 920px) {
    .admin-body {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        min-height: auto;
    }

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

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

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

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

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

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

    .analytics-breakdown-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

@media (max-width: 560px) {
    .admin-topbar,
    .panel-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .admin-nav {
        grid-template-columns: 1fr;
    }

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

    .detail-list div {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .filter-form {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .analytics-filters {
        grid-template-columns: 1fr;
    }

    .analytics-filter-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .analytics-filter-actions .button {
        width: 100%;
    }
}
