:root {
    color-scheme: light;
    font-family: "Inter", "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
    font-size: 16px;
    color: #111827;
    --brand-a: #6a6dff;
    --brand-b: #3cc1ff;
    --ink: #0f172a;
    --muted: #6b7280;
    --line: rgba(15, 23, 42, 0.08);
    --card: #ffffff;
    --bg: #f4f5f7;
    --danger: #e5484d;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(180deg, #ffffff 0%, #f4f5f7 100%);
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #eef4ff;
    color: #1a2a52;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.04em;
}

.brand-logo-link {
    display: inline-flex;
    align-items: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.brand-logo-link:hover { transform: translateY(-1px); opacity: 0.9; }
.brand-logo {
    height: 64px;
    width: auto;
    display: block;
    object-fit: contain;
}

.eyebrow {
    margin: 0 0 2px;
    font-size: 0.72rem;
    color: #7c8189;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border: none;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.95rem;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
    background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
    color: #fff;
    box-shadow: 0 12px 28px rgba(60, 193, 255, 0.22);
}
.btn-secondary { background: rgba(16, 24, 40, 0.05); color: #111827; }
.btn-ghost { background: transparent; color: #334155; border: 1px solid var(--line); }
.btn-danger { background: rgba(229, 72, 77, 0.1); color: var(--danger); }
.btn-danger:hover { background: rgba(229, 72, 77, 0.16); }
.btn-block { width: 100%; }
.btn-sm { padding: 9px 16px; font-size: 0.88rem; }
.btn-xs { padding: 6px 12px; font-size: 0.8rem; }

/* ---------- login ---------- */
.admin-login-body {
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: min(100%, 400px);
    background: var(--card);
    border-radius: 24px;
    padding: 36px 32px;
    box-shadow: 0 35px 80px rgba(15, 23, 42, 0.1);
    margin-top: 8vh;
}
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.login-title { text-align: center; margin: 0 0 26px; font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; color: #0f172a; }
.lang-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: 999px;
    border: 1px solid var(--line); background: #fff;
    color: #334155; text-decoration: none; font-weight: 600; font-size: 0.9rem;
    white-space: nowrap;
    transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.lang-pill:hover { color: #4f46e5; border-color: rgba(106, 109, 255, 0.4); transform: translateY(-1px); box-shadow: 0 8px 20px rgba(60, 193, 255, 0.15); }
.login-actions { display: flex; gap: 12px; margin-top: 22px; }
.login-actions .login-action { flex: 1; }
.forgot-lead { color: var(--muted); font-size: 0.9rem; line-height: 1.7; margin: 0 0 18px; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 6px; font-weight: 600; font-size: 0.9rem; color: #374151; }
.login-form input {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.login-form input:focus { border-color: var(--brand-a); box-shadow: 0 0 0 3px rgba(106, 109, 255, 0.15); }
.login-foot { text-align: center; margin: 20px 0 0; }
.login-foot a { color: var(--muted); text-decoration: none; font-size: 0.9rem; }

/* ---------- alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-size: 0.92rem; font-weight: 600; }
.alert-error { background: rgba(229, 72, 77, 0.1); color: #b42318; }
.alert-ok { background: rgba(34, 197, 94, 0.12); color: #15803d; }

/* ---------- admin shell ---------- */
.admin-body { background: var(--bg); }
.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px 32px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.admin-brand { display: flex; align-items: center; gap: 12px; }
.admin-brand strong { font-size: 1.05rem; }
.admin-top-actions { display: flex; align-items: center; gap: 16px; }
.lang-globe {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    color: #55585f;
    border: 1px solid var(--line);
    background: #fff;
    transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.lang-globe:hover { color: #4f46e5; border-color: rgba(106, 109, 255, 0.4); transform: translateY(-1px); }
.login-brand { position: relative; }
.login-globe { position: absolute; top: 0; right: 0; width: 34px; height: 34px; }
.admin-user { font-weight: 600; color: #374151; font-size: 0.9rem; }
.link-muted { color: var(--muted); text-decoration: none; font-size: 0.88rem; }
.link-muted:hover { color: var(--ink); }

/* admin section nav */
.admin-nav-link {
    text-decoration: none;
    color: #475569;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 8px 4px;
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
    /* Break CJK labels only at explicit <wbr> points (between words),
       never character-by-character when the mobile top bar gets tight. */
    word-break: keep-all;
    text-align: center;
    line-height: 1.25;
}
.admin-nav-link:hover { color: var(--ink); }
.admin-nav-link.active { color: #4f46e5; border-bottom-color: #6a6dff; }

/* contact list */
.page-title-row { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.count-badge {
    background: rgba(99, 102, 241, 0.1); color: #4338ca;
    font-weight: 700; font-size: 0.85rem; padding: 4px 12px; border-radius: 999px;
}
.empty-box {
    background: #fff; border-radius: 16px; padding: 40px; text-align: center;
    color: var(--muted); box-shadow: 0 16px 40px rgba(12, 24, 56, 0.05);
}
.contact-list { display: flex; flex-direction: column; gap: 12px; }
.contact-item {
    background: #fff; border-radius: 16px;
    box-shadow: 0 12px 30px rgba(12, 24, 56, 0.05);
    border: 1px solid var(--line);
    overflow: hidden;
}
.contact-item > summary {
    display: grid;
    grid-template-columns: 170px 1fr 1.2fr 1.4fr 20px;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    cursor: pointer;
    list-style: none;
    font-size: 0.92rem;
}
.contact-item > summary::-webkit-details-marker { display: none; }
.contact-item > summary:hover { background: #fafbfc; }
.contact-item .c-time { color: #94a3b8; font-size: 0.85rem; }
.contact-item .c-name { font-weight: 700; color: var(--ink); }
.contact-item .c-company { color: #475569; }
.contact-item .c-email { color: #4f46e5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-item .c-caret { color: #94a3b8; transition: transform 0.2s ease; text-align: center; }
.contact-item[open] .c-caret { transform: rotate(180deg); }

.contact-detail { padding: 4px 20px 20px; border-top: 1px solid var(--line); }
.detail-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.detail-table th, .detail-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 0.92rem; }
.detail-table th { width: 130px; color: #64748b; font-weight: 600; white-space: nowrap; }
.detail-table td { color: var(--ink); }
.detail-message { white-space: pre-wrap; line-height: 1.7; }
.detail-actions { display: flex; gap: 10px; margin-top: 16px; }

@media (max-width: 720px) {
    .contact-item > summary { grid-template-columns: 1fr auto; row-gap: 4px; }
    .contact-item .c-time { grid-column: 1 / -1; }
    .contact-item .c-email { grid-column: 1 / -1; }
    .detail-table th { width: 96px; }
}

.admin-main { max-width: 1200px; margin: 0 auto; padding: 18px 32px 60px; }
.admin-main.narrow { max-width: 720px; }

/* ---------- stat cards ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 26px; }
.stat-card {
    background: #fff;
    border-radius: 18px;
    padding: 20px 22px;
    box-shadow: 0 16px 40px rgba(12, 24, 56, 0.05);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-num { font-size: 2rem; font-weight: 800; color: var(--ink); letter-spacing: -0.03em; }
.stat-label { color: var(--muted); font-size: 0.9rem; }

/* ---------- 瀏覽人次（admin/stats.jsp）---------- */
.section-h { margin: 30px 0 14px; font-size: 1.12rem; font-weight: 700; color: var(--ink); }
.data-table td.num, .data-table th.num { text-align: right; white-space: nowrap; }
/* 長條圖欄位固定寬度，長條本身是等比例的色塊，不需要圖表函式庫。 */
.bar-col { width: 34%; }
.bar {
    display: block;
    height: 8px;
    min-width: 2px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand-a), var(--brand-b));
}
.stat-note { margin-top: 22px; font-size: 0.88rem; line-height: 1.7; }

/* ---------- toolbar ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.tabs { display: inline-flex; background: rgba(16, 24, 40, 0.05); border-radius: 999px; padding: 4px; }
.tabs .tab {
    border: none;
    background: transparent;
    padding: 8px 18px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #475569;
    text-decoration: none;
    cursor: pointer;
}
.tabs .tab.active { background: #fff; color: var(--ink); box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08); }
.search-form { display: flex; gap: 8px; align-items: center; }
.search-form input {
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    min-width: 120px;
    outline: none;
}
.search-form input:focus { border-color: var(--brand-a); }
.toolbar-actions { margin-left: auto; display: flex; gap: 10px; }

/* ---------- table ---------- */
.table-wrap { background: #fff; border-radius: 18px; overflow: hidden; box-shadow: 0 16px 40px rgba(12, 24, 56, 0.05); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table th { background: #fafbfc; color: #64748b; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table code { background: rgba(16, 24, 40, 0.05); padding: 2px 8px; border-radius: 6px; font-size: 0.85rem; }
.cell-title { font-weight: 600; color: var(--ink); }
.col-actions { white-space: nowrap; text-align: right; }
.inline-form { display: inline; }
.file-link { color: #4f46e5; text-decoration: none; font-weight: 600; }
.file-link:hover { text-decoration: underline; }
.file-size { display: block; color: var(--muted); font-size: 0.78rem; }
.muted { color: var(--muted); }
.empty-row { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; padding: 4px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.badge-manual { background: rgba(99, 102, 241, 0.12); color: #4338ca; }
.badge-driver { background: rgba(6, 182, 212, 0.14); color: #0e7490; }

/* ---------- edit form ---------- */
.crumbs { margin-bottom: 10px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.page-title { margin: 0 0 24px; font-size: 1.6rem; }
.edit-form { background: #fff; border-radius: 20px; padding: 28px; box-shadow: 0 16px 40px rgba(12, 24, 56, 0.05); }
.field { margin-bottom: 20px; }
.field > label { display: block; font-weight: 600; margin-bottom: 8px; color: #374151; font-size: 0.92rem; }
.field input[type=text], .field input:not([type]), .field input[list], .field input[type=file],
.field input[type=search], .field input[type=email], .field input[type=url],
.field input[type=tel], .field input[type=number], .field select, .field textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 0.98rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--brand-a);
    box-shadow: 0 0 0 3px rgba(106, 109, 255, 0.12);
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
/* 聯絡事項設定：每個事項一組「收件人 + 副本」，用分隔線區隔比較好讀。 */
.topic-block { padding-bottom: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.topic-block:last-of-type { border-bottom: none; margin-bottom: 8px; }
.topic-name { font-weight: 700; color: #111827; margin-bottom: 12px; }
@media (max-width: 640px) {
    .field-grid { grid-template-columns: 1fr; }
}
.req { color: var(--danger); }
.radio-row { display: flex; gap: 12px; }
.radio-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; border: 1px solid var(--line); border-radius: 999px;
    font-weight: 600; cursor: pointer;
}
.radio-pill input { accent-color: var(--brand-a); }
.current-file { margin: 10px 0 0; font-size: 0.88rem; }
.current-file a { color: #4f46e5; }
.form-actions { display: flex; gap: 12px; margin-top: 8px; }

@media (max-width: 720px) {
    .stat-row { grid-template-columns: 1fr; }
    .field-grid { grid-template-columns: 1fr; }
    .toolbar-actions { margin-left: 0; width: 100%; }
    .admin-topbar, .admin-main { padding-left: 18px; padding-right: 18px; }
    .table-wrap { overflow-x: auto; }
    /* let the search box take the full row and shrink freely, so the
       toolbar reflows to its mobile form at a wider (easier) window size */
    .search-form { width: 100%; }
    .search-form input { flex: 1; min-width: 0; }
}
