/* ===========================================================
   IG 自動貼文影片系統 — 設計系統
   科技感 × 溫暖明亮 × 大字體 × 完全 RWD
   =========================================================== */
:root {
  /* 底色：暖白，不是純白也不是灰 */
  --bg-base: #FBFAF7;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F4F6FB;

  /* 主色：靛藍紫 */
  --brand-50: #EEF0FF;
  --brand-100: #E0E3FF;
  --brand-500: #6366F1;
  --brand-600: #4F46E5;
  --brand-700: #4338CA;

  /* 輔色：溫暖珊瑚橘 */
  --accent-50: #FFF1EC;
  --accent-500: #FF7A59;
  --accent-600: #F2613F;

  --success: #10B981; --success-bg: #E7F8F1;
  --warning: #F59E0B; --warning-bg: #FEF5E7;
  --danger:  #EF4444; --danger-bg:  #FDECEC;
  --info:    #0EA5E9; --info-bg:    #E6F6FE;

  --text-primary: #1A1D29;
  --text-secondary: #4A5063;
  --text-muted: #8A90A2;
  --line: #E6E8F0;

  --gradient-hero: linear-gradient(135deg, #6366F1 0%, #A855F7 48%, #FF7A59 100%);
  --gradient-1: linear-gradient(150deg, #EEF0FF, #F3ECFF);
  --gradient-2: linear-gradient(150deg, #E7F8F1, #EAF7FF);
  --gradient-3: linear-gradient(150deg, #FFF1EC, #FFF6E8);
  --gradient-4: linear-gradient(150deg, #F3ECFF, #FFEDF6);

  --shadow-sm: 0 1px 3px rgba(99,102,241,.08);
  --shadow-md: 0 8px 24px rgba(99,102,241,.10);
  --shadow-lg: 0 20px 48px rgba(99,102,241,.16);

  --radius: 20px;
  --radius-sm: 14px;

  --fs-display: 40px; --fs-h1: 30px; --fs-h2: 24px; --fs-h3: 20px;
  --fs-body: 17px; --fs-small: 15px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, sans-serif;

  --sidebar-w: 250px;
}

html[data-fontscale="large"] {
  --fs-display: 46px; --fs-h1: 34px; --fs-h2: 27px; --fs-h3: 22px;
  --fs-body: 19px; --fs-small: 17px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.75;
  letter-spacing: .02em;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: var(--fs-h1); margin: 0 0 8px; font-weight: 800; letter-spacing: .01em; }
h2 { font-size: var(--fs-h2); margin: 0 0 10px; font-weight: 700; }
h3 { font-size: var(--fs-h3); margin: 0 0 8px; font-weight: 700; }
p  { margin: 8px 0; }
.muted { color: var(--text-muted); font-size: var(--fs-small); }
.sub { color: var(--text-secondary); font-size: var(--fs-small); }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 18px; } .mt-s { margin-top: 10px; } .mb { margin-bottom: 18px; }
.hidden { display: none !important; }
.grow { flex: 1; }

/* ---------- 登入頁 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--gradient-hero); background-attachment: fixed;
}
.login-card {
  background: var(--bg-surface); border-radius: 28px; box-shadow: var(--shadow-lg);
  padding: 44px 38px; width: 100%; max-width: 460px;
}
.login-logo {
  width: 66px; height: 66px; border-radius: 20px; background: var(--gradient-hero);
  display: flex; align-items: center; justify-content: center; font-size: 32px; margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}

/* ---------- 版面 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--bg-surface);
  border-right: 1px solid var(--line); padding: 22px 16px 28px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px; background: var(--gradient-hero);
  display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0;
}
.brand-name { font-weight: 800; font-size: 18px; line-height: 1.3; }
.brand-sub { font-size: 12px; color: var(--text-muted); letter-spacing: .08em; }

.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-weight: 600; cursor: pointer; font-size: 16px;
  min-height: 48px; transition: background .15s, color .15s, transform .15s;
  border: none; background: none; width: 100%; text-align: left; font-family: inherit;
}
.nav-item:hover { background: var(--bg-subtle); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--brand-50); color: var(--brand-700); }
.nav-item .ico { font-size: 20px; width: 24px; text-align: center; }
.nav-sep { height: 1px; background: var(--line); margin: 12px 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 28px;
  background: rgba(255,255,255,.86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40;
}
.topbar .greet { font-weight: 700; font-size: 18px; }
.content { padding: 26px 28px 80px; max-width: 1400px; width: 100%; }

.avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--gradient-hero); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-surface); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  border: 1px solid var(--line); padding: 22px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat {
  border-radius: var(--radius); padding: 20px 22px; border: 1px solid var(--line);
  box-shadow: var(--shadow-sm); transition: transform .18s, box-shadow .18s;
}
.stat:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.stat .label { font-size: var(--fs-small); color: var(--text-secondary); font-weight: 600; display: flex; gap: 8px; align-items: center; }
.stat .value { font-size: 40px; font-weight: 800; line-height: 1.2; margin: 6px 0 2px; letter-spacing: -.02em; }
.stat .foot { font-size: 14px; color: var(--text-muted); }
.stat.g1 { background: var(--gradient-1); } .stat.g2 { background: var(--gradient-2); }
.stat.g3 { background: var(--gradient-3); } .stat.g4 { background: var(--gradient-4); }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px; min-height: 48px; border-radius: var(--radius-sm); border: none;
  font-family: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  background: var(--brand-500); color: #fff; transition: filter .15s, transform .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm); text-decoration: none;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: var(--shadow-md); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.accent { background: var(--accent-500); }
.btn.ghost { background: var(--bg-subtle); color: var(--text-secondary); box-shadow: none; }
.btn.ghost:hover { background: var(--brand-50); color: var(--brand-700); }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.sm { padding: 8px 14px; min-height: 38px; font-size: 14px; border-radius: 11px; }
.btn.lg { padding: 16px 28px; min-height: 58px; font-size: 18px; width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 表單 ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; font-size: var(--fs-small); margin-bottom: 7px; color: var(--text-secondary); }
.field .hint { font-size: 13.5px; color: var(--text-muted); margin-top: 5px; line-height: 1.6; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], input[type=time], input[type=date], select, textarea {
  width: 100%; padding: 12px 15px; min-height: 50px; border: 2px solid var(--line);
  border-radius: var(--radius-sm); font-family: inherit; font-size: 16px; /* ≥16px 避免 iOS 縮放 */
  background: var(--bg-surface); color: var(--text-primary); transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 130px; line-height: 1.8; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--brand-50);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8'%3E%3Cpath fill='%238A90A2' d='M1 1l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; padding-right: 42px; }

.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; cursor: pointer; font-size: 16px; }
.check input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand-500); cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; background: var(--bg-subtle); border: 2px solid transparent;
  font-size: 15px; cursor: pointer; font-weight: 600; color: var(--text-secondary); user-select: none;
  min-height: 40px; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--brand-50); }
.chip.on { background: var(--brand-50); border-color: var(--brand-500); color: var(--brand-700); }
.chip .x { opacity: .6; font-weight: 800; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  font-size: 13.5px; font-weight: 700; background: var(--bg-subtle); color: var(--text-secondary);
  white-space: nowrap;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--success-bg); color: #067a55; }
.badge.warn { background: var(--warning-bg); color: #96650a; }
.badge.err { background: var(--danger-bg); color: #c02626; }
.badge.info { background: var(--info-bg); color: #0369a1; }
.badge.brand { background: var(--brand-50); color: var(--brand-700); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-small); }
th { text-align: left; padding: 13px 14px; background: var(--bg-subtle); font-weight: 700; color: var(--text-secondary); white-space: nowrap; }
th:first-child { border-radius: 12px 0 0 12px; } th:last-child { border-radius: 0 12px 12px 0; }
td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FCFCFE; }

/* ---------- 清單 ---------- */
.list-item {
  display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); margin-bottom: 10px; background: var(--bg-surface);
}
.list-item:hover { border-color: var(--brand-100); background: #FCFCFE; }
.thumb {
  width: 56px; height: 74px; border-radius: 10px; object-fit: cover; background: var(--bg-subtle);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--text-muted);
}
.thumb.wide { width: 74px; height: 56px; }

/* ---------- 素材網格 ---------- */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.asset-card {
  border: 2px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-surface);
  cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.asset-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.asset-card.sel { border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--brand-50); }
.asset-card .ph {
  aspect-ratio: 9/16; background: var(--bg-subtle) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 34px; color: var(--text-muted); position: relative;
}
.asset-card .meta { padding: 10px 12px; font-size: 13.5px; }
.asset-card .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-card .ph .tag { position: absolute; top: 8px; left: 8px; }

/* ---------- AI 文案卡 ---------- */
.variant {
  border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 18px; margin-bottom: 14px;
  background: var(--bg-surface); transition: border-color .15s, box-shadow .15s;
}
.variant:hover { border-color: var(--brand-100); }
.variant.sel { border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--brand-50); background: #FDFDFF; }
.variant .vh { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.variant pre {
  white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 15.5px;
  line-height: 1.85; margin: 0; color: var(--text-primary);
}

/* ---------- 時間軸 ---------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 8px 0; font-size: var(--fs-small); }
.tl-item::before {
  content: ''; position: absolute; left: -23px; top: 15px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--brand-500); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--brand-100);
}
.tl-item.warn::before { background: var(--warning); box-shadow: 0 0 0 2px var(--warning-bg); }
.tl-item.error::before { background: var(--danger); box-shadow: 0 0 0 2px var(--danger-bg); }

/* ---------- 趨勢圖 ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; }
.bar { width: 100%; max-width: 46px; border-radius: 8px 8px 3px 3px; background: var(--brand-500); min-height: 4px; transition: height .4s; }
.bar.fail { background: var(--danger); }
.bar-label { font-size: 12.5px; color: var(--text-muted); }

/* ---------- 對話框 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(26,29,41,.45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal {
  background: var(--bg-surface); border-radius: 24px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto; padding: 28px;
}
.modal.wide { max-width: 860px; }

/* ---------- 提示 ---------- */
#toasts { position: fixed; top: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 10px; max-width: min(92vw, 400px); }
.toast {
  background: var(--bg-surface); border-left: 6px solid var(--brand-500); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 14px 18px; font-size: 15.5px; animation: slideIn .25s ease;
  line-height: 1.7;
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.notice { padding: 14px 18px; border-radius: var(--radius-sm); font-size: var(--fs-small); line-height: 1.75; margin-bottom: 16px; }
.notice.info { background: var(--info-bg); color: #0b5c86; }
.notice.warn { background: var(--warning-bg); color: #8a5d09; }
.notice.err { background: var(--danger-bg); color: #b02323; }
.notice.ok { background: var(--success-bg); color: #056c4b; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty .ico { font-size: 54px; margin-bottom: 12px; opacity: .55; }

/* 步驟指示 */
.steps { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.step { flex: 1; min-width: 120px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bg-subtle); font-size: 14.5px; font-weight: 700; color: var(--text-muted); }
.step.on { background: var(--brand-50); color: var(--brand-700); }
.step.done { background: var(--success-bg); color: #067a55; }

.switch { position: relative; display: inline-block; width: 56px; height: 32px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #CBD0E0; border-radius: 32px; transition: .2s; }
.slider:before { content: ''; position: absolute; height: 26px; width: 26px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider:before { transform: translateX(24px); }

.mobile-only { display: none; }
.bottom-nav { display: none; }

/* =================== RWD =================== */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  :root {
    --fs-display: 32px; --fs-h1: 26px; --fs-h2: 22px; --fs-h3: 19px;
    --fs-body: 18px; --fs-small: 16px;
  }
  html[data-fontscale="large"] { --fs-body: 20px; --fs-small: 18px; --fs-h1: 29px; }

  .sidebar { display: none; }
  .mobile-only { display: block; }
  .content { padding: 18px 16px 110px; }
  .topbar { padding: 12px 16px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .stat { padding: 14px 14px; }
  .stat .value { font-size: 30px; }
  .stat .label { font-size: 14px; }
  .stat .foot { font-size: 12.5px; }

  .list-item { flex-wrap: wrap; }
  .list-item .btn-row { width: 100%; margin-top: 8px; }
  .list-item .btn-row .btn { flex: 1; }
  .list-item .grow { flex-basis: 60%; }
  .card { padding: 18px 16px; border-radius: 18px; }
  .stat .value { font-size: 34px; }
  .btn { width: 100%; min-height: 54px; font-size: 17px; }
  .btn.sm { width: auto; min-height: 42px; }
  .btn-row .btn { width: auto; flex: 1; min-width: 120px; }
  .modal { padding: 20px 16px; border-radius: 20px; max-height: 92vh; }
  .asset-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  table { font-size: 15px; }
  th, td { padding: 10px 8px; }

  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(99,102,241,.08);
  }
  .bottom-nav button {
    flex: 1; border: none; background: none; font-family: inherit; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px;
    color: var(--text-muted); font-size: 12px; font-weight: 700; min-height: 56px; border-radius: 12px;
  }
  .bottom-nav button .ico { font-size: 22px; }
  .bottom-nav button.active { color: var(--brand-600); background: var(--brand-50); }
}

@media (max-width: 420px) {
  .login-card { padding: 32px 22px; border-radius: 22px; }
  .asset-grid { grid-template-columns: repeat(2, 1fr); }
}

/* 無障礙 */
:focus-visible { outline: 3px solid var(--brand-500); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
