/* MicroTec AI 管理層 —— 老闆一個人看的頁面。
   大字（17px 起）、大按鈕（52px 起）、手機優先（390px 可用），
   品牌藍 #235887 / #3780C3，紅色只用在警告。 */

:root {
  --brand-deep: #235887;
  --brand: #3780C3;
  --brand-soft: #e4eef8;
  /* 品牌藍當「文字色」用的那一份：深色模式下 #235887 壓在深底上看不清，要換成亮一階的藍 */
  --brand-ink: #235887;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2630;
  --muted: #5d6b7a;
  --line: #d9e0e8;
  --ok: #2e7d4f;
  --ok-soft: #e2f3e8;
  --warn: #b42318;
  --warn-soft: #fde8e6;
  --pending-soft: #eef0f3;
  --shadow: 0 1px 3px rgba(20, 40, 60, .08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: #1b3550;
    --brand-ink: #9cc7f0;
    --bg: #0f1620;
    --card: #182230;
    --text: #e8edf2;
    --muted: #9fb0c0;
    --line: #2b3a4a;
    --ok: #6cc795;
    --ok-soft: #173327;
    --warn: #ff8a80;
    --warn-soft: #3a1f1d;
    --pending-soft: #222d3a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html { font-size: 17px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ── 頂欄 / 頁腳 ─────────────────────────────────────────── */

.topbar {
  background: var(--brand-deep);
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.topbar .date { font-size: .95rem; opacity: .9; white-space: nowrap; }

.footer {
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  font-size: .8rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.footer .link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px 0; min-height: 44px; }

.app { flex: 1; padding: 16px; max-width: 760px; width: 100%; margin: 0 auto; }
/* 會議室與會議畫面：橢圓桌要夠寬才排得開十三個座位 */
.app.wide { max-width: 1100px; }

.loading, .empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ── 通用元件 ─────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  gap: 8px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand-ink); border-color: var(--line); }
.btn.danger { background: var(--card); color: var(--warn); border-color: var(--warn); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .btn { flex: 1 1 140px; }

.input, .textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 1.05rem;
}
.textarea { resize: vertical; min-height: 64px; }
.input:focus, .textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.live { background: var(--brand-soft); color: var(--brand-ink); }
.pill.pending { background: var(--pending-soft); color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 8px; border-radius: 13px;
  background: var(--warn); color: #fff; font-size: .85rem; font-weight: 700;
}

.msg { padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-size: .95rem; }
.msg.error { background: var(--warn-soft); color: var(--warn); }
.msg.info { background: var(--brand-soft); color: var(--brand-ink); }

.muted { color: var(--muted); font-size: .92rem; }
.small { font-size: .85rem; }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 20px 0 10px; color: var(--brand-ink); }
h3 { font-size: 1.02rem; margin: 14px 0 6px; }

/* ── 登入 ─────────────────────────────────────────────────── */

.login { max-width: 420px; margin: 40px auto; }
.login .card { padding: 24px 20px; }
.login label { display: block; font-weight: 600; margin: 14px 0 6px; }
.login .input { font-size: 1.2rem; letter-spacing: .05em; }
.login .code { font-size: 1.6rem; letter-spacing: .3em; text-align: center; }

/* ── 經理頁 ─────────────────────────────────────────────── */

.mhead { display: grid; grid-template-columns: 110px 1fr; gap: 16px; align-items: start; }
.mhead .avatar { width: 110px; height: 110px; border-radius: 50%; object-fit: cover; background: var(--pending-soft); }
.mhead.is-gm .avatar { height: 138px; border-radius: 12px; }
.mhead h1 { margin: 0 0 4px; }
.mhead dl { margin: 10px 0 0; font-size: .92rem; }
.mhead dt { color: var(--muted); font-weight: 600; }
.mhead dd { margin: 0 0 6px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 4px 0 12px; padding-bottom: 2px; }
.tab {
  flex: 1 0 auto; min-height: 52px; padding: 8px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab.active { background: var(--brand-deep); color: #fff; border-color: var(--brand-deep); }
.tab .badge { height: 22px; min-width: 22px; font-size: .78rem; }

.decision { border-left: 4px solid var(--brand); padding-left: 12px; margin: 14px 0; }
.decision .title { font-weight: 700; font-size: 1.05rem; }
.decision .detail { margin: 6px 0; }
.decision .suggested { color: var(--brand-ink); font-size: .95rem; }
.decision.approved { border-left-color: var(--ok); }
.decision.rejected { border-left-color: var(--muted); }
.decision .textarea { margin-top: 8px; }

.chase li { margin: 6px 0; }

/* ── 問答 ─────────────────────────────────────────────────── */

.chat { margin-top: 20px; }
.chat .log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble { padding: 12px 14px; border-radius: 14px; max-width: 94%; }
.bubble.user { align-self: flex-end; background: var(--brand); color: #fff; }
.bubble.user .md a { color: #fff; }
.bubble.assistant { align-self: flex-start; background: var(--brand-soft); color: var(--text); }
.bubble.gm { align-self: flex-start; background: var(--card); border: 1px solid var(--brand); }
.bubble .who { font-size: .8rem; font-weight: 700; opacity: .8; margin-bottom: 4px; }
.bubble.thinking { color: var(--muted); font-style: italic; }
.chat form { display: flex; flex-direction: column; gap: 10px; }
.chat .row { display: flex; gap: 10px; }
.chat .row .input { flex: 1; }
.chat .row .btn { flex: 0 0 auto; min-width: 88px; }
.chat .opts { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .95rem; color: var(--muted); }
.chat .opts input { width: 22px; height: 22px; }

/* ── Markdown ─────────────────────────────────────────────── */

.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 1.3em; }
.md li { margin: 4px 0; }
.md h1, .md h2, .md h3 { margin: 12px 0 6px; font-size: 1.05rem; color: var(--brand-ink); }
.md code { background: var(--pending-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.md pre { background: var(--pending-soft); padding: 10px; border-radius: 10px; overflow-x: auto; font-size: .85rem; }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md strong { font-weight: 700; }

/* ── 會議室 ───────────────────────────────────────────────── */

.hint { display: flex; align-items: center; gap: 12px; }
.hint > div { flex: 1; }
.hint-close { flex: 0 0 auto; min-height: 52px; }

.room { position: relative; margin-bottom: 14px; }
.room-table { display: none; }

.seat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 52px; padding: 10px 6px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text); text-align: center; width: 100%;
}
.seat-face { position: relative; display: block; width: 64px; height: 64px; flex: 0 0 auto; }
.seat-avatar {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; object-position: center top; display: block;
  background: var(--pending-soft); border: 3px solid var(--line);
}
.seat-badge { position: absolute; top: -6px; right: -8px; height: 24px; min-width: 24px; padding: 0 6px; font-size: .8rem; border: 2px solid var(--card); }
.seat-name { font-weight: 700; font-size: .88rem; line-height: 1.3; margin-top: 4px; }
.seat-status { font-size: .78rem; color: var(--muted); line-height: 1.3; }

/* 狀態環：有事 = 品牌藍粗環 + 紅色數字；已匯報沒事 = 細灰環；尚未接入 = 整個褪色 */
.seat.has-items .seat-avatar { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.seat.has-items .seat-status { color: var(--brand-ink); font-weight: 600; }
.seat.is-off .seat-avatar { filter: grayscale(1); opacity: .55; }
.seat.is-off .seat-name { color: var(--muted); }
.seat.speaking .seat-avatar { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand); }
.seat.speaking .seat-face { transform: scale(1.18); transform-origin: 50% 100%; z-index: 2; }
/* 放大的頭像加上外環會壓到名字，名字往下讓一點 */
.seat.speaking .seat-name { margin-top: 10px; color: var(--brand-ink); }
.room.compact:not(.oval) .seat.speaking .seat-face { transform: scale(1.1); transform-origin: 50% 50%; }
.room.compact:not(.oval) .seat.speaking .seat-avatar { box-shadow: 0 0 0 3px var(--brand); }
.seat.addressed { outline: 3px dashed var(--brand); outline-offset: 2px; }
.seat-face { transition: transform .2s ease; }
@media (prefers-reduced-motion: reduce) { .seat-face { transition: none; } }

.room-center { text-align: center; margin: 12px 0 4px; }
.room-kicker { font-size: .82rem; font-weight: 700; color: var(--brand-ink); letter-spacing: .12em; }
.room-line { font-weight: 600; margin: 2px 0 10px; }
.room-meeting .room-line { margin-bottom: 2px; }
.start-btn { width: 100%; min-height: 60px; font-size: 1.15rem; background: var(--brand-deep); border-color: var(--brand-deep); }

/* 窄螢幕：總經理一列在最上面，底下每個團隊兩欄 */
.seat-gm { flex-direction: row; justify-content: center; gap: 14px; padding: 14px; flex-wrap: wrap; }
.seat-gm .seat-face { width: 84px; height: 84px; }
.seat-gm .seat-name { font-size: 1.1rem; margin: 0; }
.room-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.room-group-title { grid-column: 1 / -1; font-weight: 700; color: var(--brand-ink); margin-top: 12px; }

/* 會議進行中（窄螢幕）：桌子縮成一排頭像，位置留給發言 */
.room.compact:not(.oval) { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px 4px; align-items: center; }
.room.compact:not(.oval) .room-group { display: contents; }
.room.compact:not(.oval) .room-group-title,
.room.compact:not(.oval) .seat-name,
.room.compact:not(.oval) .seat-status { display: none; }
.room.compact:not(.oval) .seat { border: 0; background: transparent; padding: 0; min-height: 56px; justify-content: center; }
.room.compact:not(.oval) .seat-face { width: 52px; height: 52px; }
.room.compact:not(.oval) .seat-badge { height: 20px; min-width: 20px; font-size: .72rem; top: -5px; right: -6px; }
.room.compact:not(.oval) .room-center { grid-column: 2 / -1; text-align: left; margin: 0; padding-left: 8px; }

/* 寬螢幕：橢圓桌。座位的位置由 meeting.js 算好寫進 left/top（依容器實際寬度） */
.room.oval { height: 560px; }
.room.oval.compact { height: 400px; }
.room.oval .room-table {
  display: block; position: absolute; border-radius: 50%;
  background: var(--brand-soft); border: 2px solid var(--line); box-shadow: inset 0 0 0 10px var(--card), var(--shadow);
}
.room.oval .room-group { display: contents; }
.room.oval .seat {
  position: absolute; transform: translate(-50%, -50%); width: 136px; padding: 0; gap: 0;
  border: 0; background: transparent; flex-direction: column; flex-wrap: nowrap;
}
.room.oval .seat-face, .room.oval .seat-gm .seat-face { width: 64px; height: 64px; }
.room.oval .seat-gm .seat-face { width: 76px; height: 76px; }
.room.oval .seat-name, .room.oval .seat-gm .seat-name { font-size: .82rem; margin-top: 4px; white-space: nowrap; }
.room.oval .seat-gm .seat-name { font-size: .95rem; }
.room.oval.compact .seat-face { width: 54px; height: 54px; }
.room.oval.compact .seat-gm .seat-face { width: 62px; height: 62px; }
.room.oval.compact .seat-status { display: none; }
.room.oval .room-center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 340px; max-width: 40%; margin: 0;
}
.room.oval .room-group-title {
  position: absolute; top: 50%; transform: translateY(-50%); margin: 0;
  font-size: .8rem; color: var(--muted); white-space: nowrap;
}
.room.oval .side-us .room-group-title { left: 182px; }
.room.oval .side-cn .room-group-title { right: 182px; }

.room-links { margin-bottom: 14px; }
.card > h2:first-child { margin-top: 0; }

/* ── 每日會議 ─────────────────────────────────────────────── */

.speech { border-left: 5px solid var(--brand); }
.speech.is-gm { border-left-color: var(--brand-deep); }
.speech-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.speech-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; object-position: center top; background: var(--pending-soft); flex: 0 0 auto; }
.speech-name { font-weight: 700; font-size: 1.1rem; }
/* 發言用大字：老闆是隔著桌子「聽」的，不是湊近看報表 */
.speech-text { font-size: 1.2rem; line-height: 1.7; }
.speech-text p:last-child { margin-bottom: 0; }
.speech-cards h3 { color: var(--brand-ink); }

.meet-controls { margin-top: 0; }
.meet-toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; margin: 10px 0 14px; }
.toggle { display: inline-flex; align-items: center; gap: 10px; min-height: 52px; font-weight: 600; cursor: pointer; }
.toggle input { width: 24px; height: 24px; accent-color: var(--brand); }

.say { display: flex; flex-direction: column; gap: 10px; }
.say-row { display: flex; gap: 10px; }
.say-row .input { flex: 1; min-width: 0; }
.say-row .btn { flex: 0 0 auto; min-width: 88px; }
.mic { width: 100%; min-height: 60px; touch-action: none; user-select: none; -webkit-user-select: none; }
.mic.is-on { background: var(--brand-deep); color: #fff; border-color: var(--brand-deep); }

.transcript { max-height: 60vh; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 14px; }
.tline { display: flex; gap: 10px; align-items: flex-start; }
.tline-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; object-position: center top; background: var(--pending-soft); flex: 0 0 auto; }
.tline-avatar.boss { display: inline-flex; align-items: center; justify-content: center; background: var(--brand-deep); color: #fff; font-weight: 700; font-size: .9rem; }
.tline-body { flex: 1; min-width: 0; }
.tline-who { font-size: .82rem; font-weight: 700; color: var(--muted); }
.tline.is-boss .tline-body { background: var(--brand-soft); border-radius: 12px; padding: 8px 12px; }
.tline .md p:last-child { margin-bottom: 0; }

.mrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-decoration: none; color: inherit; min-height: 72px; }
.mrow-title { font-weight: 700; }

/* ── 待辦追蹤 ─────────────────────────────────────────────── */

.action-head { display: flex; align-items: center; gap: 10px; }
.action-head h2 { margin: 0; }
.action-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 6px 0; }
