:root {
  --blue: #3f6fc4;
  --blue-l: #5887da;
  --blue-d: #2d5aa8;
  --blue-soft: #eef3fc;
  --ink: #1f2430;
  --ink-2: #4b5160;
  --ink-3: #5b6170;
  --line: #e6e8ee;
  --bg: #f5f6f9;
  --panel: #ffffff;
  --ok: #1a7f55;
  --ok-soft: #e7f5ee;
  --err: #c23b3b;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 8px 24px rgba(20, 30, 60, 0.06);
  font-family: Inter, "Noto Sans TC", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); }
.btn-ghost { background: var(--panel); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #cfd4df; background: #fafbfd; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px; color: var(--ink-3); flex: 0 0 auto; }
.icon-btn:hover { background: #f0f2f6; color: var(--ink); }
.form-error { color: var(--err); font-size: 13px; margin: 8px 0 0; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, #e6eefc 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 36px 28px 28px; box-shadow: var(--shadow); text-align: center; }
.login-logo { width: 180px; height: auto; }
.login-title { font-weight: 700; letter-spacing: .32em; text-transform: uppercase; font-size: 12px; color: var(--blue); margin-top: 4px; }
.login-sub { color: var(--ink-3); font-size: 13px; margin: 6px 0 24px; }
.login-card input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; margin-bottom: 12px; outline: none; }
.login-card input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(63,111,196,.15); }

/* App shell */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 20px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand img { height: 40px; width: auto; }
.brand-tag { font-size: 10.5px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--blue); background: var(--blue-soft); padding: 4px 8px; border-radius: 6px; }
.search { flex: 1 1 360px; max-width: 640px; display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px 0 14px; background: #f3f5f9; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-3); transition: border-color .15s, background .15s, box-shadow .15s; }
.search:focus-within { background: #fff; border-color: #b9cbef; box-shadow: 0 0 0 4px rgba(63,111,196,.10); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 15px; color: var(--ink); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd { font: inherit; font-size: 12px; color: var(--ink-3); border: 1px solid #d9dde6; border-radius: 6px; padding: 1px 7px; background: #fff; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--ink-3); flex: 0 0 auto; }
.top-right b { color: var(--ink); }

.body { flex: 1; min-height: 0; display: flex; }
.browser { flex: 1; min-width: 0; overflow-y: auto; padding: 20px 24px 40px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 13px; color: var(--ink); }
.chip span { opacity: .7; margin-left: 4px; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip:not(.on):hover { border-color: #c9cfdb; }
.sortbox { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sort-label { font-size: 13px; color: var(--ink-3); }
.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { height: 30px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; color: var(--ink-3); }
.seg button.on { background: var(--blue-soft); color: var(--blue-d); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 1240px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.grid .card-body { padding: 10px 12px 12px; }
.grid .card-name { font-size: 14px; }
.view-seg button { width: 34px; padding: 0; display: grid; place-items: center; }
.card { padding: 0; border-radius: 14px; overflow: hidden; background: #fff; border: 1px solid var(--line); text-align: left; box-shadow: 0 1px 2px rgba(20,30,60,.04); transition: box-shadow .15s, transform .15s, border-color .15s; display: flex; flex-direction: column; }
.card:hover { box-shadow: 0 8px 24px rgba(20,30,60,.08); transform: translateY(-1px); }
.card.on { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue), 0 10px 28px rgba(63,111,196,.28); transform: translateY(-2px); }
.thumb { position: relative; aspect-ratio: 16 / 10; display: grid; place-items: center; color: #fff; font-size: 28px; font-weight: 700; letter-spacing: -.02em; overflow: hidden; background: #e9ecf2; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.editing { position: absolute; left: 10px; bottom: 10px; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: 0; color: #fff; background: var(--blue); padding: 5px 10px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.editing::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }

/* List view */
.list { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: #fff; text-align: left; width: 100%; position: relative; }
.row:last-child { border-bottom: 0; }
.row:hover { background: #f8f9fc; }
.row.on { background: var(--blue-soft); }
.row.on::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--blue); }
.row .thumb { width: 96px; flex: 0 0 96px; aspect-ratio: 16 / 10; border-radius: 8px; font-size: 16px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-name small { font-weight: 500; color: var(--ink-3); margin-left: 6px; font-size: 12px; }
.row-domain { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-when { flex: 0 0 auto; font-size: 12px; color: var(--ink-3); width: 92px; text-align: right; }
.row .editing { position: static; box-shadow: none; padding: 3px 9px; font-size: 11.5px; }
.thumb .tag { position: absolute; top: 10px; right: 10px; font-size: 11px; font-weight: 600; color: var(--ink); background: rgba(255,255,255,.92); padding: 3px 8px; border-radius: 999px; letter-spacing: 0; }
.thumb .busy { position: absolute; top: 10px; left: 10px; font-size: 11px; font-weight: 600; color: #7a4d00; background: #fff3d6; padding: 3px 8px; border-radius: 999px; letter-spacing: 0; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { flex: 0 0 auto; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: var(--ink-3); background: #eef0f4; }
.badge.live { color: var(--ok); background: var(--ok-soft); }
.card-domain { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-when { font-size: 12px; color: var(--ink-3); }
.empty-grid { text-align: center; color: var(--ink-3); padding: 60px 0; }
.mono { display: grid; place-items: center; color: #fff; font-weight: 700; border-radius: 10px; }
.mono.sm { width: 40px; height: 40px; flex: 0 0 40px; font-size: 14px; }

/* Panel */
.panel { width: clamp(460px, 36vw, 620px); flex: 0 0 clamp(460px, 36vw, 620px); background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel-empty { margin: auto; text-align: center; padding: 24px 32px; color: var(--ink-3); }
.panel-empty img { width: 52px; height: 52px; }
.panel-empty h2 { font-size: 18px; color: var(--ink); margin: 14px 0 6px; }
.panel-empty p { font-size: 14px; line-height: 1.6; margin: 0; }
.panel-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: 14px; padding: 16px 14px 16px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--blue-soft), #fff); border-top: 4px solid var(--blue); }
.panel-thumb { position: relative; width: 104px; height: 65px; flex: 0 0 104px; border-radius: 10px; overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; box-shadow: 0 0 0 1px rgba(20,30,60,.08), 0 4px 12px rgba(20,30,60,.10); }
.panel-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.editing-label { font-size: 11px; font-weight: 700; letter-spacing: .14em; color: var(--blue); text-transform: uppercase; margin-bottom: 2px; }
.back-btn { display: none; }
.panel-title { flex: 1; min-width: 0; }
.proj-name { font-weight: 700; font-size: 19px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-domain { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 44px; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.menu button:hover { background: #f4f6fa; }

.thread { flex: 1; overflow-y: auto; padding: 18px 16px 8px; background: #f8f9fb; display: flex; flex-direction: column; gap: 14px; }
.thread-empty { margin: auto; text-align: center; color: var(--ink-3); font-size: 14px; line-height: 1.6; padding: 0 8px; }
.thread-empty .chips { justify-content: center; margin-top: 14px; }
.thread-empty .chip { height: auto; min-height: 36px; padding: 8px 12px; text-align: left; }
.msg-user { align-self: flex-end; max-width: 88%; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble { background: var(--blue-l); color: #fff; padding: 10px 14px; border-radius: 16px 16px 4px 16px; font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.bubble.system { background: #e9ecf2; color: var(--ink-2); font-size: 13px; }
.msg-imgs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-imgs img { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.card-msg { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-msg.error { border-color: #f1caca; background: #fff8f8; }
.card-msg.error .msg-text { color: #8f2727; }
.done-head { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ok); }
.msg-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; margin: 0; }
.msg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.msg-meta { margin-left: auto; font-size: 12px; color: var(--ink-3); }

.progress-title { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-3); }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.step { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--ink-3); }
.step .dot { width: 18px; height: 18px; flex: 0 0 18px; border-radius: 50%; border: 2px solid #d3d7e0; display: grid; place-items: center; }
.step.active { color: var(--ink); font-weight: 600; }
.step.active .dot { border-color: var(--blue); border-top-color: transparent; animation: spin .8s linear infinite; }
.step.done .dot { border-color: var(--ok); background: var(--ok); }
.step.done .dot::after { content: ""; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.bar { height: 4px; background: #eef0f5; border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #8fb2ee); border-radius: 4px; transition: width .8s ease; }

.composer { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.composer-box { display: flex; align-items: flex-end; gap: 4px; border: 1px solid var(--line); border-radius: 14px; padding: 5px; transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: #b9cbef; box-shadow: 0 0 0 4px rgba(63,111,196,.10); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; font-size: 15px; line-height: 1.5; padding: 8px 4px; max-height: 180px; min-width: 0; }
.send-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--blue); color: #fff; display: grid; place-items: center; flex: 0 0 40px; }
.send-btn:disabled { opacity: .35; cursor: default; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; }
.attachments:not(:empty) { margin-bottom: 8px; }
.att { position: relative; width: 56px; height: 56px; }
.att img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.att button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; font-size: 13px; line-height: 1; }
.dragover .composer-box { border-color: var(--blue); border-style: dashed; }

/* Dialog */
.dialog { border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(20,30,60,.25); }
.dialog::backdrop { background: rgba(20,24,36,.35); }
.dialog form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.dialog h3 { margin: 0 0 4px; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.dialog label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.dialog input:not([type=checkbox]) { height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-weight: 400; background: #fff; outline: none; }
.dialog input:focus { border-color: var(--blue); }
.dialog input[type=checkbox] { width: 18px; height: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.lightbox { position: fixed; inset: 0; background: rgba(10,12,20,.8); display: grid; place-items: center; z-index: 50; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Tablet / phone */
@media (max-width: 980px) {
  .panel { position: fixed; inset: 0; width: auto; z-index: 20; border-left: 0; transform: translateX(100%); transition: transform .22s ease; }
  .app.chat-open .panel { transform: none; }
  .panel-empty { display: none !important; }
  .back-btn { display: grid; }
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 14px; }
  .brand img { height: 32px; }
  .search { order: 3; flex: 1 1 100%; max-width: none; }
  .search kbd { display: none; }
  .browser { padding: 14px 14px 32px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .thumb { font-size: 22px; }
  .row-when { display: none; }
  .panel-thumb { width: 72px; height: 45px; flex-basis: 72px; }
  .proj-name { font-size: 17px; }
  .composer textarea { font-size: 16px; }
}
