/* ═══════════════════════════════════════
   AIPGM 共用主題系統 theme.css
   在每個 HTML 的 <head> 加入：
   <link rel="stylesheet" href="theme.css">
   （mimiya_manager 子目錄用 ../theme.css）
═══════════════════════════════════════ */

/* ── 字型 ── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;700&family=DM+Mono:wght@400;500&family=Space+Mono:wght@400;700&display=swap');

/* ── 基礎變數（不隨主題變化）── */
:root {
  --bg:        #ffffff;
  --bg2:       #f7f7f6;
  --bg3:       #f0efed;
  --bg4:       #e8e6e3;
  --border:    rgba(0,0,0,0.09);
  --border2:   rgba(0,0,0,0.16);
  --border3:   rgba(0,0,0,0.24);
  --text:      #1a1a1a;
  --text2:     #6b6b6b;
  --text3:     #a0a0a0;
  --green:     #1D9E75;
  --green-lt:  #E1F5EE;
  --red:       #A32D2D;
  --red-lt:    #FCEBEB;
  --amber:     #b45309;
  --amber-lt:  #FAEEDA;
  --radius:    8px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 6px 24px rgba(0,0,0,0.10);
  --font:      'Noto Sans TC', sans-serif;
  --font-mono: 'DM Mono', 'Space Mono', monospace;
}

/* ── 主題：紫色（預設）── */
:root,
[data-theme="purple"] {
  --accent:      #5b4de0;
  --accent2:     #7c6dfa;
  --accent3:     #9d91ff;
  --accent-lt:   rgba(91,77,224,0.08);
  --accent-lt2:  rgba(91,77,224,0.15);
  --accent-b:    rgba(91,77,224,0.25);
  --accent-fg:   #ffffff;
}

/* ── 主題：青綠 ── */
[data-theme="teal"] {
  --accent:      #0d766a;
  --accent2:     #0f9080;
  --accent3:     #14b8a6;
  --accent-lt:   rgba(13,118,106,0.08);
  --accent-lt2:  rgba(13,118,106,0.15);
  --accent-b:    rgba(13,118,106,0.25);
  --accent-fg:   #ffffff;
}

/* ── 主題：藍 ── */
[data-theme="blue"] {
  --accent:      #1d4ed8;
  --accent2:     #2563eb;
  --accent3:     #3b82f6;
  --accent-lt:   rgba(29,78,216,0.08);
  --accent-lt2:  rgba(29,78,216,0.15);
  --accent-b:    rgba(29,78,216,0.25);
  --accent-fg:   #ffffff;
}

/* ── 主題：玫瑰 ── */
[data-theme="rose"] {
  --accent:      #9f1239;
  --accent2:     #be123c;
  --accent3:     #e11d48;
  --accent-lt:   rgba(159,18,57,0.08);
  --accent-lt2:  rgba(159,18,57,0.15);
  --accent-b:    rgba(159,18,57,0.25);
  --accent-fg:   #ffffff;
}

/* ── 主題：琥珀 ── */
[data-theme="amber"] {
  --accent:      #92400e;
  --accent2:     #b45309;
  --accent3:     #d97706;
  --accent-lt:   rgba(146,64,14,0.08);
  --accent-lt2:  rgba(146,64,14,0.15);
  --accent-b:    rgba(146,64,14,0.25);
  --accent-fg:   #ffffff;
}

/* ── 主題：綠 ── */
[data-theme="green"] {
  --accent:      #166534;
  --accent2:     #15803d;
  --accent3:     #16a34a;
  --accent-lt:   rgba(22,101,52,0.08);
  --accent-lt2:  rgba(22,101,52,0.15);
  --accent-b:    rgba(22,101,52,0.25);
  --accent-fg:   #ffffff;
}

/* ── 共用基礎樣式 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); }

/* ── 共用按鈕 ── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--bg2); color: var(--text2);
  font-size: 13px; font-family: var(--font);
  cursor: pointer; transition: all 0.15s;
}
.btn:hover { background: var(--bg3); color: var(--text); }
.btn-primary, .btn.primary {
  background: var(--accent); color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover, .btn.primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-danger, .btn.danger {
  background: var(--red-lt); color: var(--red); border-color: rgba(163,45,45,0.2);
}
.btn-sm, .btn.sm { padding: 4px 10px; font-size: 12px; }

/* ── 共用卡片 ── */
.theme-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

/* ── 共用輸入框 ── */
.theme-input,
input[type=text], input[type=number], input[type=date],
input[type=email], input[type=url], input[type=search],
select, textarea {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 13px; padding: 7px 10px;
  font-family: var(--font); outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-b);
  box-shadow: 0 0 0 3px var(--accent-lt);
}

/* ── 主題切換器 ── */
#theme-switcher {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
}
#theme-toggle-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  border: none; cursor: pointer; font-size: 18px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s;
}
#theme-toggle-btn:hover { transform: scale(1.1); }
#theme-palette {
  position: absolute; bottom: 48px; right: 0;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); padding: 12px;
  display: none; flex-direction: column; gap: 8px;
  box-shadow: var(--shadow-lg); min-width: 140px;
}
#theme-palette.open { display: flex; }
#theme-palette .t-label {
  font-size: 10px; color: var(--text3);
  font-family: var(--font-mono); letter-spacing: 0.08em;
  text-transform: uppercase; margin-bottom: 2px;
}
.theme-swatch-row { display: flex; gap: 6px; }
.theme-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { border-color: var(--text); }

/* ════════════════════════════════════════════════════════
   SHARED COMPONENT SYSTEM
   使用 :where() 包裝 → 零特異性，各頁自訂樣式永遠優先
════════════════════════════════════════════════════════ */

/* ── Layout ── */
:where(.shell) { display: flex; min-height: 100vh; }

:where(.sidebar) {
  width: 220px; flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0;
  height: 100vh; overflow-y: auto; z-index: 50;
}
:where(.brand) { padding: 16px 18px 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
:where(.brand-gem) { font-size: 20px; margin-bottom: 4px; }
:where(.brand-name) { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.3; }
:where(.brand-sub) { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }

:where(.nav-item) {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; margin: 1px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text2);
  cursor: pointer; transition: background 0.12s, color 0.12s;
  font-family: var(--font);
}
:where(.nav-item:hover) { background: var(--accent-lt); color: var(--accent); }
:where(.nav-item.active) { background: var(--accent-lt2); color: var(--accent); font-weight: 500; }
:where(.nav-icon) { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
:where(.sidebar-bottom) { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); }
:where(.sidebar-note) { font-size: 11px; color: var(--text3); line-height: 1.5; margin-bottom: 8px; }

:where(.main) { margin-left: 220px; flex: 1; background: var(--bg2); min-height: 100vh; }
:where(.topbar) {
  background: rgba(255,255,255,0.94); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 28px; height: 54px;
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
}
:where(.page-title) { font-size: 16px; font-weight: 600; color: var(--text); }
:where(.page-sub) { font-size: 12.5px; color: var(--text2); margin-top: 1px; }
:where(.content) { padding: 22px 28px; }

/* ── Cards ── */
:where(.card) {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
:where(.card-title) {
  font-size: 15px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 14px;
}
:where(.panel) { display: none; }
:where(.panel.active) { display: block; }

/* ── Metrics ── */
:where(.metrics) { display: grid; grid-template-columns: repeat(auto-fit,minmax(140px,1fr)); gap: 10px; margin-bottom: 18px; }
:where(.met) { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; }
:where(.met-label) { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
:where(.met-val) { font-family: var(--font-mono); font-size: 20px; font-weight: 600; color: var(--text); line-height: 1; }

/* ── Form Layout ── */
:where(.form-grid) { display: grid; gap: 10px; }
:where(.g2) { grid-template-columns: 1fr 1fr; }
:where(.g3) { grid-template-columns: 1fr 1fr 1fr; }
:where(.g4) { grid-template-columns: 1fr 1fr 1fr 1fr; }
:where(.field) { display: flex; flex-direction: column; gap: 4px; }
:where(label) { font-size: 12px; color: var(--text2); font-weight: 500; letter-spacing: 0.02em; }
:where(.two-col) { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* ── Tables ── */
:where(.tbl-wrap) { overflow-x: auto; }
:where(table) { width: 100%; border-collapse: collapse; font-size: 13.5px; }
:where(th) { text-align: left; padding: 7px 10px; font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
:where(td) { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
:where(tr:last-child td) { border-bottom: none; }
:where(tr:hover td) { background: var(--bg2); }
:where(.td-mono) { font-family: var(--font-mono); font-size: 13px; }
:where(.td-red) { color: var(--red); font-family: var(--font-mono); font-size: 13px; }
:where(.td-green) { color: var(--green); font-family: var(--font-mono); font-size: 13px; font-weight: 500; }
:where(.td-gold) { color: var(--amber); font-family: var(--font-mono); font-size: 13px; font-weight: 500; }

/* ── Badges ── */
:where(.badge) { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
:where(.badge.rose) { background: #F5E6EC; color: #8B4360; }
:where(.badge.teal) { background: #E0F2EF; color: #2D7A6E; }
:where(.badge.gold) { background: #F7F0DC; color: #7a5e10; }
:where(.badge.gray) { background: var(--bg3); color: var(--text2); }
:where(.badge.accent) { background: var(--accent-lt2); color: var(--accent); }

/* ── Info boxes ── */
:where(.info) { background: #F5E6EC; border: 1px solid rgba(139,67,96,0.25); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; color: #8B4360; line-height: 1.55; margin-bottom: 12px; }
:where(.info.teal) { background: #E0F2EF; border-color: rgba(45,122,110,0.25); color: #2D7A6E; }
:where(.info.gold) { background: #F7F0DC; border-color: rgba(181,148,42,0.3); color: #7a5e10; }
:where(.info.accent) { background: var(--accent-lt); border-color: var(--accent-b); color: var(--accent); }
:where(.info.green) { background: var(--green-lt); border-color: rgba(29,158,117,0.25); color: #115740; }

/* ── Button extensions ── */
:where(.btn.teal) { background: #2D7A6E; color: #fff; border-color: #2D7A6E; }
:where(.btn.teal:hover) { background: #246357; }
:where(.btn.gold) { background: #B5942A; color: #fff; border-color: #B5942A; }
:where(.btn.full) { width: 100%; justify-content: center; }

/* ── Sub-tabs ── */
:where(.subtabs) { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
:where(.stab) { padding: 7px 16px; font-size: 13px; border: none; background: none; cursor: pointer; color: var(--text2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: var(--font); transition: color 0.12s; }
:where(.stab:hover) { color: var(--text); }
:where(.stab.on) { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
:where(.subpanel) { display: none; }
:where(.subpanel.on) { display: block; }

/* ── Section heading ── */
:where(.sec-head) { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text3); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
:where(.sec-head::after) { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Separator ── */
:where(.sep) { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ── Outbox ── */
:where(.outbox) { background: var(--text); color: #e8e6e3; border-radius: var(--radius-sm); padding: 14px 16px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; white-space: pre-wrap; max-height: 320px; overflow-y: auto; word-break: break-word; }

/* ── Upload area ── */
:where(.upload-area) { border: 2px dashed var(--border2); border-radius: var(--radius-sm); padding: 14px; text-align: center; cursor: pointer; transition: border-color 0.15s; font-size: 13px; color: var(--text2); }
:where(.upload-area:hover) { border-color: var(--accent); color: var(--accent); }
:where(.upload-area.has-file) { border-color: var(--green); background: var(--green-lt); color: #115740; }

/* ── Placeholder ── */
:where(.placeholder) { color: var(--text3); font-size: 14px; text-align: center; padding: 28px 0; }

/* ── Toast ── */
:where(.toast) { position: fixed; bottom: 22px; right: 22px; background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13.5px; z-index: 9999; opacity: 0; transform: translateY(8px); transition: all 0.25s; pointer-events: none; max-width: 280px; }
:where(.toast.show) { opacity: 1; transform: translateY(0); }

/* ── Copy row ── */
:where(.copy-row) { display: flex; gap: 7px; margin-top: 8px; flex-wrap: wrap; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.14); border-radius: 4px; }

/* ── Responsive ── */
@media(max-width:820px) {
  :where(.two-col) { grid-template-columns: 1fr; }
  :where(.form-grid.g3), :where(.form-grid.g4) { grid-template-columns: 1fr 1fr; }
  :where(.sidebar) { display: none; }
  :where(.main) { margin-left: 0; }
}
