/* Segian Reptile — 後台。前台是逛的，後台是操作的：密度高、狀態一眼看得出來。 */

.admin { background: var(--ground); }

/* ── 登入 ── */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--canopy); }
.gate-box { background: var(--surface); border-radius: 4px; padding: 34px 32px 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35); }
.gate-brand { font-family: var(--mono); font-size: 10px; letter-spacing: 0.34em; color: var(--moss); }
.gate-box h1 { margin: 0; font-family: var(--serif); font-size: 24px; letter-spacing: 0.14em; }
.gate-box label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.gate-box input { border: 1px solid var(--line); border-radius: 2px; background: var(--surface-2); color: var(--ink); font: inherit; padding: 9px 11px; }
.gate-note { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.8; }
.gate-note code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 2px; }

/* ── 按鈕 ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 2px; padding: 7px 14px; font-size: 13px; border: 1px solid transparent; white-space: nowrap; }
.btn--primary { background: var(--ember); color: var(--ember-ink); font-weight: 500; }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { border-color: var(--line); color: var(--ink-2); background: var(--surface); }
.btn--ghost:hover { border-color: var(--moss); color: var(--ink); }
.btn--danger { border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); background: transparent; }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; filter: none; }

/* ── 頂列 ── */
.abar { background: var(--canopy); color: var(--canopy-ink); display: flex; align-items: center; gap: 24px; padding: 0 20px; position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.abrand { font-family: var(--serif); font-size: 15px; letter-spacing: 0.22em; padding: 14px 0; }
.abrand em { font-style: normal; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.28em; color: var(--moss); margin-left: 6px; }
.atabs { display: flex; gap: 2px; }
.atabs button { padding: 15px 15px 13px; font-size: 13.5px; opacity: 0.75; border-bottom: 2px solid transparent; }
.atabs button:hover { opacity: 1; }
.atabs button.on { opacity: 1; border-bottom-color: var(--ember); font-weight: 500; }
.abar-r { margin-left: auto; display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.abar .btn--ghost { background: transparent; border-color: rgba(255, 255, 255, 0.2); color: var(--canopy-ink); }
.abar .btn--ghost:hover { border-color: var(--ember); color: #fff; }
.driver { font-size: 11px; opacity: 0.6; }

.page { max-width: 1320px; margin: 0 auto; padding: 22px 20px 60px; display: flex; flex-direction: column; gap: 18px; }

/* ── KPI ── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 15px 16px; display: flex; flex-direction: column; gap: 3px; }
.kpi .k { font-size: 11px; letter-spacing: 0.1em; color: var(--muted); }
.kpi .v { font-family: var(--mono); font-size: 26px; font-weight: 500; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11.5px; color: var(--muted); }
.kpi--alert { border-color: color-mix(in srgb, var(--hold) 55%, transparent); }
.kpi--alert .v { color: var(--hold); }

/* ── 區塊 ── */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.box { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.box h2 { margin: 0; font-family: var(--serif); font-size: 14px; letter-spacing: 0.1em; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: baseline; gap: 8px; }
.box h2 em { font-style: normal; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em; color: var(--moss); text-transform: uppercase; }
.box-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.8; }
.hint code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 2px; }

/* 形態分布長條 */
.bar { display: grid; grid-template-columns: 7.5em 1fr 2.2em; align-items: center; gap: 10px; font-size: 12.5px; }
.bar .t { color: var(--ink-2); }
.bar .track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--moss); border-radius: 999px; }
.bar .fill.gene { background: var(--ember); }
.bar .n { font-family: var(--mono); font-size: 11.5px; color: var(--muted); text-align: right; }

/* 庫齡清單 */
.age-row { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 7px 0; border-bottom: 1px dashed var(--line-soft); }
.age-row:last-child { border-bottom: 0; }
.age-row .code { font-family: var(--mono); font-size: 11px; color: var(--moss); }
.age-row .d { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--hold); }

/* ── 工具列 ── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar select, .toolbar input[type="file"] {
  border: 1px solid var(--line); border-radius: 2px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; padding: 7px 10px;
}
.toolbar input[type="search"] { min-width: 220px; }
.grow { flex: 1; }
.count { font-size: 12px; color: var(--muted); }

/* ── 表格 ── */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px; }
.table th { text-align: left; font-weight: 500; font-size: 11.5px; letter-spacing: 0.06em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--ink); }
.table th.num, .table td.num { text-align: right; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table .mini { width: 34px; height: 42px; border-radius: 2px; overflow: hidden; background: var(--surface-2); }
.table .mini svg, .table .mini img { width: 100%; height: 100%; display: block; object-fit: cover; }
.table .code { font-family: var(--mono); font-size: 11.5px; color: var(--moss); }
.table .nm { font-family: var(--serif); font-size: 14px; }
.table .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table .stale { color: var(--hold); }
.rowbtns { display: flex; gap: 6px; justify-content: flex-end; }
.rowbtns button { border: 1px solid var(--line); border-radius: 2px; padding: 3px 9px; font-size: 12px; color: var(--ink-2); background: var(--surface); }
.rowbtns button:hover { border-color: var(--moss); color: var(--ink); }
.table .empty td { text-align: center; color: var(--muted); padding: 44px 12px; }

/* ── 訂單 ── */
.orders { display: flex; flex-direction: column; gap: 12px; }
.order { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 10px 18px; }
.order .no { font-family: var(--mono); font-size: 12.5px; color: var(--moss); }
.order .who { font-size: 14px; }
.order .who b { font-family: var(--serif); font-weight: 500; }
.order .meta { font-size: 12px; color: var(--muted); }
.order .lines { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.order .line { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; color: var(--ink-2); }
.order .right { text-align: right; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.order .total { font-family: var(--mono); font-size: 17px; font-weight: 500; }
.order select { border: 1px solid var(--line); border-radius: 2px; background: var(--surface); color: var(--ink); font: inherit; font-size: 12.5px; padding: 4px 8px; }
.order .note { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border-left: 2px solid var(--moss); padding: 8px 11px; line-height: 1.7; }
.orders .empty { text-align: center; color: var(--muted); padding: 60px 20px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* modal 開啟時底層不跟著捲。綁 dialog[open] 而不是 JS class：
   dialog 的 close 事件是非同步派送的，用 class 會有一段時間解不了鎖。 */
html:has(dialog[open]) { overflow: hidden; padding-right: var(--sbw, 0px); }

/* ── 編輯視窗 ── */
.editor { border: 0; border-radius: 4px; padding: 0; width: min(920px, 94vw); max-height: 92vh; overflow: hidden; overscroll-behavior: contain; background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); }
.editor::backdrop { background: rgba(10, 16, 13, 0.6); backdrop-filter: blur(2px); }
.ed-form { display: flex; flex-direction: column; max-height: 92vh; }
.ed-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; border-bottom: 1px solid var(--line-soft); }
.ed-head h2 { margin: 0; font-family: var(--serif); font-size: 17px; letter-spacing: 0.08em; }
.close { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 15px; color: var(--ink-2); }
.ed-body { display: grid; grid-template-columns: 240px 1fr; gap: 22px; padding: 20px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.ed-media { display: flex; flex-direction: column; gap: 10px; }
.ed-preview { aspect-ratio: 4 / 5; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 2px; overflow: hidden; }
.ed-preview svg, .ed-preview img { width: 100%; height: 100%; display: block; object-fit: cover; }
.ed-preview .previewzoom { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.ed-photos { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-photos figure { position: relative; margin: 0; width: 54px; height: 54px; border-radius: 2px; overflow: hidden; border: 1px solid var(--line); }
.ed-photos figure.on { border-color: var(--moss); box-shadow: 0 0 0 2px var(--moss); }
.ed-photos .pick { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
.ed-photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ed-photos figure:not(.on) .pick:hover img { opacity: 0.82; }
.ed-photos .cover { position: absolute; left: 0; bottom: 0; right: 0; background: rgba(0, 0, 0, 0.62); color: #fff; font-size: 9.5px; letter-spacing: 0.06em; text-align: center; line-height: 1.5; pointer-events: none; }
.ed-photos .rm { position: absolute; top: 1px; right: 1px; width: 17px; height: 17px; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 11px; line-height: 1; display: grid; place-items: center; }

.ed-phototools { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.ed-phototools .pos { font-size: 11.5px; color: var(--muted); font-family: var(--mono); margin-right: auto; }
.ed-phototools button { border: 1px solid var(--line); border-radius: 2px; background: var(--surface-2); color: var(--ink-2); font-size: 11.5px; padding: 3px 8px; }
.ed-phototools button:hover:not(:disabled) { border-color: var(--moss); color: var(--ink); }
.ed-phototools button:disabled { opacity: 0.4; cursor: default; }

/* 放大檢視 */
.lightbox { border: 0; padding: 0; background: none; max-width: 96vw; max-height: 96vh; overflow: visible; overscroll-behavior: contain; }
.lightbox::backdrop { background: rgba(6, 10, 8, 0.82); }
.lightbox img { display: block; max-width: 92vw; max-height: 82vh; border-radius: 3px; cursor: zoom-out; background: var(--surface-2); }
.lbbar { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 0 0; color: #e9efe6; }
.lbbar span { font-family: var(--mono); font-size: 12px; min-width: 56px; text-align: center; }
.lbbar button { border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 2px; background: rgba(255, 255, 255, 0.08); color: #fff; font-size: 13px; padding: 3px 12px; }
.lbbar button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.lbbar button:disabled { opacity: 0.35; cursor: default; }
.upload { cursor: pointer; }
.ed-uploads { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-uploads .btn { flex: 1 1 auto; justify-content: center; font-size: 12px; padding: 7px 10px; }
.ed-media { position: relative; border: 1px dashed transparent; border-radius: 2px; transition: border-color 0.15s, background 0.15s; }
.ed-media.is-drop { border-color: var(--moss); background: var(--surface-2); }
.ed-media.is-drop .ed-preview { opacity: 0.5; }
.ed-media.is-busy { opacity: 0.65; pointer-events: none; }
.ed-media kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 2px; padding: 0 3px; }

/* 表現標籤（複選） */
.traitbox { border: 1px solid var(--line); border-radius: 2px; padding: 8px 11px 10px; margin: 0; min-width: 0; }
.traitbox legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.traitbox legend .hint { font-size: 11px; }
.traitrow { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: baseline; padding: 3px 0; }
.traitrow__h { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }
.traitchips { display: flex; flex-wrap: wrap; gap: 5px; }
.traitchip { cursor: pointer; position: relative; display: inline-block; }
.traitchip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.traitchip span { display: inline-flex; align-items: baseline; gap: 4px; border: 1px solid var(--line); border-radius: 2px; padding: 3px 8px; font-size: 12px; color: var(--ink-2); background: var(--surface-2); }
.traitchip em { font-style: normal; font-size: 10px; color: var(--muted); }
.traitchip input:checked + span { background: var(--moss); border-color: var(--moss); color: #fff; }
.traitchip input:checked + span em { color: rgba(255, 255, 255, 0.75); }
.traitchip input:focus-visible + span { outline: 2px solid var(--moss); outline-offset: 1px; }

/* 列表裡的標籤 */
.tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.tag { font-size: 10.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 2px; padding: 0 4px; line-height: 1.6; }

.ed-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; align-content: start; }
.ed-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ed-fields .span2 { grid-column: 1 / -1; }
.ed-fields input, .ed-fields select, .ed-fields textarea {
  border: 1px solid var(--line); border-radius: 2px; background: var(--surface-2); color: var(--ink); font: inherit; font-size: 13px; padding: 7px 10px; width: 100%;
}
.ed-fields textarea { resize: vertical; }
.ed-fields input:invalid:not(:placeholder-shown) { border-color: var(--danger); }
.ed-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line-soft); background: var(--surface-2); }

@media (max-width: 900px) {
  .two { grid-template-columns: 1fr; }
  .ed-body { grid-template-columns: 1fr; }
  .ed-fields { grid-template-columns: 1fr; }
  .order { grid-template-columns: 1fr; }
  .order .right { align-items: flex-start; text-align: left; }
}
