/* ============================================================
   Gateway control room — 後台專用樣式
   與前台 gateway.css 完全解耦：前台改版不會波及後台，反之亦然。
   ============================================================ */

:root {
    --bg: #0b1210;
    --surface: #141d1a;
    --surface-2: #1a2622;
    --surface-3: #21302b;
    --line: rgba(255, 255, 255, .09);
    --line-strong: rgba(255, 255, 255, .18);
    --ink: #eaf2ec;
    --muted: #93a89c;
    --dim: #6f857a;
    --accent: #a7dec1;
    --accent-dim: rgba(167, 222, 193, .12);
    --danger: #e8857a;
    --danger-dim: rgba(232, 133, 122, .12);
    --gold: #e3b87a;
    --radius: 12px;
    --sans: -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
    --serif: Georgia, "Times New Roman", serif;
    --mono: ui-monospace, Consolas, "SF Mono", monospace;
}

* { box-sizing: border-box; }

/* .card 是 display:grid，會蓋掉 hidden 屬性的預設值，所以這裡強制 */
[hidden] { display: none !important; }

html, body { background: var(--bg); }

body.admin-body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ---------- 頂部 ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: min(1080px, calc(100% - 40px));
    margin: 0 auto;
    padding: 20px 0;
    border-bottom: 1px solid var(--line);
}

.topbar .brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-family: var(--serif);
    font-size: 20px;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.topbar .brand small {
    color: var(--dim);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.topnav { display: flex; align-items: center; gap: 4px; }

.topnav a {
    padding: 7px 11px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    transition: color .15s, background .15s, border-color .15s;
}

.topnav a:hover { color: var(--ink); background: var(--surface-2); }
.topnav a.is-current { color: var(--ink); border-color: var(--line-strong); }

/* ---------- 版面 ---------- */

.wrap {
    width: min(1080px, calc(100% - 40px));
    margin: 0 auto;
    padding: 36px 0 90px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 26px;
}

.page-head h1 {
    margin: 0 0 6px;
    font-family: var(--serif);
    font-size: 36px;
    font-weight: 400;
    line-height: 1.1;
    letter-spacing: -.02em;
}

.muted { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- 按鈕 ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.btn:hover { background: var(--surface-2); border-color: var(--accent); }

.btn.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #0e1a15;
    font-weight: 500;
}

.btn.primary:hover { filter: brightness(1.08); }

.btn.danger { color: var(--danger); border-color: rgba(232, 133, 122, .35); }
.btn.danger:hover { background: var(--danger-dim); border-color: var(--danger); }

.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }

/* 舊 class 相容（password.php 仍在用） */
.admin-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 15px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
}

.admin-button:hover { background: var(--surface-2); border-color: var(--accent); }
.admin-button.primary { background: var(--accent); border-color: var(--accent); color: #0e1a15; font-weight: 500; }
.admin-button.danger:hover { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }

/* ---------- 工具列 ---------- */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.search {
    position: relative;
    flex: 1 1 220px;
    max-width: 320px;
}

.search input {
    width: 100%;
    padding: 9px 12px 9px 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: 13px;
    outline: 0;
}

.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--dim); }

.search::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    width: 12px;
    height: 12px;
    margin-top: -7px;
    border: 1.5px solid var(--dim);
    border-radius: 50%;
    pointer-events: none;
}

.search::after {
    content: "";
    position: absolute;
    left: 21px;
    top: 50%;
    width: 5px;
    height: 1.5px;
    margin-top: 2px;
    background: var(--dim);
    transform: rotate(45deg);
    pointer-events: none;
}

.filters { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
}

.chip:hover { color: var(--ink); border-color: var(--line-strong); }

.chip.is-active {
    border-color: var(--accent);
    background: var(--accent-dim);
    color: var(--accent);
}

.chip b { font-weight: 500; font-family: var(--mono); font-size: 11px; opacity: .8; }

/* ---------- 專案卡片 ---------- */

.list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.card {
    display: grid;
    grid-template-columns: 26px 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 15px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color .15s, background .15s, opacity .2s, transform .2s;
}

.card:hover { border-color: var(--line-strong); background: var(--surface-2); }

.card[data-visible="0"] { opacity: .55; }
.card[data-visible="0"]:hover { opacity: .8; }

.card.is-featured { border-left: 2px solid var(--gold); }

.card.is-dragging { opacity: .4; transform: scale(.995); }

.card.is-drop-target { border-color: var(--accent); background: var(--accent-dim); }

.grip {
    display: grid;
    place-items: center;
    width: 26px;
    height: 34px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    line-height: 1;
    cursor: grab;
    user-select: none;
}

.grip:hover { color: var(--muted); background: var(--surface-3); }
.grip:active { cursor: grabbing; }

.card-body { min-width: 0; }

.card-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 15px;
    line-height: 1.3;
}

.card-title .icon { color: var(--gold); font-family: var(--serif); font-size: 15px; }

.card-title a { overflow-wrap: break-word; }
.card-title a:hover { color: var(--accent); }

.card-desc {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.5;
    overflow-wrap: break-word;
}

.card-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.tag {
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--dim);
    font-family: var(--mono);
    font-size: 10.5px;
    white-space: nowrap;
}

.tag.accent { border-color: rgba(167, 222, 193, .3); color: var(--accent); }
.tag.gold { border-color: rgba(227, 184, 122, .3); color: var(--gold); }

.card-side {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 開關 */

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 38px;
    height: 22px;
    flex: 0 0 auto;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.switch span {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    /* 讓點擊穿透到底層的 checkbox，否則 span 會攔掉事件 */
    pointer-events: none;
    transition: background .18s, border-color .18s;
}

.switch span::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--dim);
    transition: transform .18s, background .18s;
}

.switch input:checked + span { background: var(--accent-dim); border-color: rgba(167, 222, 193, .45); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.no-js .switch { display: none; }

/* 選單 */

.menu { position: relative; }

.menu summary {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    list-style: none;
}

.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-3); }
.menu[open] summary { border-color: var(--accent); color: var(--accent); }

.menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
    min-width: 168px;
    padding: 5px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface-2);
    box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

.menu-panel a,
.menu-panel button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover { background: var(--surface-3); }

.menu-panel .danger { color: var(--danger); }
.menu-panel .danger:hover { background: var(--danger-dim); }

.menu-sep { height: 1px; margin: 5px 6px; background: var(--line); }

/* ---------- 空狀態 ---------- */

.empty {
    padding: 60px 20px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

/* ---------- 抽屜 ---------- */

.drawer {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    justify-content: flex-end;
}

.drawer[hidden] { display: none; }

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(3, 8, 6, .6);
    opacity: 0;
    transition: opacity .22s;
}

.drawer-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(560px, 100%);
    height: 100%;
    border-left: 1px solid var(--line-strong);
    background: var(--surface);
    transform: translateX(24px);
    opacity: 0;
    transition: transform .24s cubic-bezier(.2, .8, .2, 1), opacity .24s;
}

.drawer.is-open .drawer-backdrop { opacity: 1; }
.drawer.is-open .drawer-panel { transform: none; opacity: 1; }

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
    margin: 0;
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 400;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.drawer-close {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

.drawer-close:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- 表單 ---------- */

.form-card {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.drawer-body .form-card { padding: 0; border: 0; background: transparent; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

.field label {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: .01em;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 14px;
    outline: 0;
    transition: border-color .15s;
}

.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--accent); }

.field textarea { min-height: 94px; resize: vertical; line-height: 1.6; }

.field .hint { color: var(--dim); font-size: 11.5px; }

.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 13px;
}

.check-row label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check-row input { accent-color: var(--accent); width: 15px; height: 15px; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.form-actions .spacer { flex: 1; }

.form-error {
    margin: 0 0 16px;
    padding: 10px 13px;
    border-left: 3px solid var(--danger);
    border-radius: 0 8px 8px 0;
    background: var(--danger-dim);
    color: #f2c4bd;
    font-size: 13px;
}

.flash {
    margin: 0 0 20px;
    padding: 11px 14px;
    border-left: 3px solid var(--accent);
    border-radius: 0 8px 8px 0;
    background: var(--accent-dim);
    color: #cdeee0;
    font-size: 13px;
}

/* ---------- 舊版頁面標題（password.php 用） ---------- */

.admin-title {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.admin-title h1 {
    margin: 0 0 6px;
    font-family: var(--serif);
    font-size: 32px;
    font-weight: 400;
}

.admin-muted { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- 登入 ---------- */

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

.login-card {
    width: min(400px, 100%);
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.login-card h1 {
    margin: 0 0 8px;
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 400;
}

.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.login-card .field { margin-top: 14px; }
.login-card .admin-button,
.login-card .btn { width: 100%; margin-top: 18px; justify-content: center; }
.login-foot { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--dim); font-size: 12px; line-height: 1.8; }
.login-foot code { display: inline-block; margin-top: 4px; padding: 3px 6px; border-radius: 5px; background: var(--bg); color: var(--muted); font-family: var(--mono); font-size: 11px; overflow-wrap: break-word; }
.login-back { margin: 20px 0 0; font-size: 12.5px; }
.login-back a { color: var(--dim); }
.login-back a:hover { color: var(--accent); }

/* ---------- 手機 ---------- */

@media (max-width: 720px) {
    .topbar { align-items: flex-start; padding: 16px 0; }
    .topbar .brand { font-size: 17px; }
    .topbar .brand small { display: none; }
    .topnav { flex-wrap: wrap; justify-content: flex-end; gap: 2px; }
    .topnav a { padding: 6px 8px; font-size: 12px; }

    .wrap { padding: 24px 0 70px; }

    .page-head { align-items: flex-start; flex-direction: column; gap: 14px; }
    .page-head h1 { font-size: 28px; }
    .page-head .btn.primary { width: 100%; }

    .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
    /* 注意：column 方向下 flex-basis 是「高度」，沿用 220px 會把搜尋框拉成一大塊 */
    .search { flex: 0 0 auto; max-width: none; }
    .filters { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }

    .card {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "body side"
            "meta meta";
        row-gap: 10px;
        padding: 14px;
    }

    .grip { display: none; }
    .card-body { grid-area: body; }
    .card-side { grid-area: side; align-self: start; }
    .card-meta { grid-area: meta; margin-top: 0; }

    .card-title { font-size: 14.5px; }
    .card-desc { font-size: 12.5px; }

    .menu-panel { min-width: 190px; }

    .drawer-panel { width: 100%; border-left: 0; }
    .drawer-body { padding: 16px; }
    .drawer-head { padding: 14px 16px; }

    .form-grid { grid-template-columns: 1fr; }
    .field.full { grid-column: auto; }

    .form-actions { flex-wrap: wrap; }
    .form-actions .btn,
    .form-actions .admin-button { flex: 1 1 auto; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
