:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #e3e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --success: #067647;
  --success-soft: #ecfdf3;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --shadow: 0 16px 42px rgba(16, 24, 40, .08);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 86% 0%, rgba(37, 99, 235, .09), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
.hidden { display: none !important; }

.app-shell { width: 100%; min-width: 0; min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }

.sidebar {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 26px 18px 20px;
  color: #fff;
  background: linear-gradient(180deg, #101828 0%, #172554 100%);
}

.brand-block { display: flex; align-items: center; gap: 12px; padding: 0 10px 28px; }
.brand-block strong { display: block; font-size: 18px; letter-spacing: .02em; }
.brand-block span { display: block; margin-top: 3px; color: #a9b8d6; font-size: 12px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px;
  background: linear-gradient(135deg, #60a5fa, #2563eb); font-weight: 850; box-shadow: 0 10px 25px rgba(37, 99, 235, .35);
}

.nav-list { display: grid; gap: 8px; }
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 11px; padding: 12px 13px;
  border: 0; border-radius: 11px; color: #cbd5e1; background: transparent; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: #fff; color: #172554; font-weight: 750; box-shadow: 0 8px 22px rgba(0,0,0,.16); }
.nav-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 8px; background: rgba(255,255,255,.1); font-size: 12px; font-weight: 850; }
.nav-item.active .nav-icon { color: #fff; background: var(--primary); }

.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px; color: #a9b8d6; font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #32d583; box-shadow: 0 0 0 4px rgba(50,213,131,.12); }

.content { width: 100%; min-width: 0; padding: 34px clamp(22px, 4vw, 58px) 72px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 7px; color: var(--primary); font-size: 11px; font-weight: 850; letter-spacing: .16em; }
h1 { margin: 0; font-size: clamp(25px, 3vw, 34px); }
h2, h3, p { margin-top: 0; }
.cloud-badge { display: flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid #b2ccff; border-radius: 999px; color: #1849a9; background: #eff4ff; font-size: 13px; font-weight: 750; }
.cloud-badge span { width: 8px; height: 8px; border-radius: 50%; background: #2e90fa; }

.view { display: none; }
.view.active { display: block; animation: enter .2s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

.page-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.page-intro h2 { margin-bottom: 7px; font-size: 21px; }
.page-intro p { margin-bottom: 0; color: var(--muted); line-height: 1.6; }
.ready-label, .planned-label { flex: 0 0 auto; padding: 7px 10px; border-radius: 8px; font-size: 12px; font-weight: 800; }
.ready-label { color: var(--success); background: var(--success-soft); }
.planned-label { color: var(--warning); background: var(--warning-soft); }

.split-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr); gap: 22px; align-items: start; }
.card { padding: 24px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.97); box-shadow: var(--shadow); }
.sticky-card { position: sticky; top: 24px; }
.section-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.section-heading.compact { margin-top: 30px; }
.section-heading > span { width: 31px; height: 31px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; color: #fff; background: var(--primary); font-size: 11px; font-weight: 850; }
.section-heading h3 { margin: 1px 0 3px; font-size: 16px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { color: #344054; font-size: 13px; font-weight: 750; }
.field small { color: var(--muted); font-size: 11px; line-height: 1.5; }
input, select, textarea {
  width: 100%; border: 1px solid #d0d5dd; border-radius: 10px; outline: none; background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input, select { height: 43px; padding: 0 12px; }
textarea { padding: 11px 12px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: #84adff; box-shadow: 0 0 0 4px rgba(37,99,235,.10); }
input[readonly], textarea[readonly] { background: #f8fafc; }
.prefix-input { display: grid; grid-template-columns: auto 1fr; align-items: center; border: 1px solid #d0d5dd; border-radius: 10px; overflow: hidden; background: #fff; }
.prefix-input:focus-within { border-color: #84adff; box-shadow: 0 0 0 4px rgba(37,99,235,.10); }
.prefix-input span { padding-left: 12px; color: var(--muted); font-weight: 750; }
.prefix-input input { border: 0; box-shadow: none; }

.result-rich-editor {
  min-height: 124px; padding: 11px 12px; overflow-wrap: anywhere; white-space: pre-wrap;
  border: 1px solid #d0d5dd; border-radius: 10px; outline: none; background: #fff; color: var(--text);
  line-height: 1.55; transition: border-color .15s, box-shadow .15s, background .15s;
}
.result-rich-editor:focus, .result-rich-editor.dragging {
  border-color: #84adff; background: #fbfdff; box-shadow: 0 0 0 4px rgba(37,99,235,.10);
}
.result-rich-editor:empty::before { content: attr(data-placeholder); color: #98a2b3; pointer-events: none; }
.result-editor-image {
  position: relative; margin: 12px 0 4px; padding: 8px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg);
}
.result-editor-image img {
  display: block; width: 100%; max-height: 360px; object-fit: contain; border-radius: 7px; background: #eef2f7;
}
.result-editor-image figcaption { margin-top: 7px; padding-right: 38px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.result-editor-image-remove {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border: 0; border-radius: 8px;
  color: var(--danger); background: var(--danger-soft); font-size: 19px; font-weight: 850; line-height: 1;
}
.jira-description-preview { min-height: 430px; max-height: 640px; overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text); }
.description-preview-empty { margin: 0; color: var(--muted); line-height: 1.6; }
.description-preview-section + .description-preview-section { margin-top: 22px; }
.description-preview-section h4 { margin: 0 0 9px; font-size: 16px; color: var(--text); }
.description-preview-copy { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.description-preview-gallery { display: grid; gap: 12px; margin-top: 12px; }
.description-preview-gallery figure { margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.description-preview-gallery img { display: block; width: 100%; max-height: 360px; object-fit: contain; border-radius: 7px; background: #eef2f7; }
.description-preview-gallery figcaption { margin-top: 7px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.description-preview-image { margin: 12px 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.description-preview-image img { display: block; width: 100%; max-height: 360px; object-fit: contain; border-radius: 7px; background: #eef2f7; }
.description-preview-image figcaption { margin-top: 7px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.actions, .inline-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.inline-actions { margin-top: 10px; }
.button { min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px; font-weight: 750; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.ghost { color: #344054; border-color: #d0d5dd; background: #fff; }
.button.soft { color: #1849a9; background: var(--primary-soft); }

.output-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.output-head span:first-child { color: var(--primary); font-size: 10px; font-weight: 900; letter-spacing: .14em; }
.output-head h3 { margin: 5px 0 0; font-size: 18px; }
.mini-state { padding: 6px 9px; border-radius: 8px; color: var(--muted); background: #f2f4f7; font-size: 11px; font-weight: 800; }
.mini-state.ready { color: var(--success); background: var(--success-soft); }
.field-note { margin-top: 16px; padding: 11px 12px; border-radius: 10px; color: var(--muted); background: #f8fafc; font-size: 12px; line-height: 1.5; }

.jira-connection {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; padding: 13px;
  border: 1px solid #fedf89; border-radius: 12px; background: #fffaeb;
}
.jira-connection.connected { border-color: #abefc6; background: var(--success-soft); }
.jira-connection.not-configured { border-color: #fecdca; background: var(--danger-soft); }
.jira-connection-copy { min-width: 0; display: flex; align-items: center; gap: 10px; }
.jira-connection-copy strong, .jira-connection-copy small { display: block; }
.jira-connection-copy strong { color: #344054; font-size: 13px; }
.jira-connection-copy small { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; }
.connection-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #f79009; box-shadow: 0 0 0 4px rgba(247,144,9,.12); }
.connection-dot.connected { background: #12b76a; box-shadow: 0 0 0 4px rgba(18,183,106,.12); }
.jira-connection-actions { flex: 0 0 auto; display: flex; gap: 7px; }
.jira-connection-actions .button { min-height: 34px; padding: 0 11px; font-size: 12px; }
.jira-result { display: grid; gap: 5px; margin-top: 12px; padding: 12px; border: 1px solid #abefc6; border-radius: 10px; background: var(--success-soft); font-size: 13px; }
.jira-result strong { color: var(--success); }
.jira-result a { width: fit-content; color: var(--primary); font-weight: 750; }
.jira-result small { color: var(--warning); line-height: 1.5; }
.jira-result.error { border-color: #fecdca; color: var(--danger); background: var(--danger-soft); }

.notice { margin-top: 18px; padding: 12px 14px; border: 1px solid #fedf89; border-radius: 11px; color: #7a2e0e; background: var(--warning-soft); font-size: 13px; line-height: 1.6; }
.weekly-top-grid { grid-template-columns: 240px 1fr; }
.weekly-board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.weekly-group { min-height: 170px; padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.92); }
.weekly-group-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.weekly-group-head h3 { margin: 0; font-size: 14px; }
.weekly-count { min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 11px; font-weight: 850; }
.weekly-empty { color: #98a2b3; font-size: 12px; }
.weekly-items { display: grid; gap: 10px; }
.weekly-item { padding: 11px; border: 1px solid #eaecf0; border-radius: 10px; background: #fff; }
.weekly-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.weekly-source { min-width: 0; overflow: hidden; color: var(--primary); font-size: 12px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.remove-item { border: 0; color: var(--danger); background: transparent; font-size: 12px; }
.weekly-item input, .weekly-item select { height: 36px; margin-top: 7px; font-size: 12px; }
.weekly-item label { display: block; color: var(--muted); font-size: 11px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.settings-grid .warning-card { grid-column: 1 / -1; }
.people-list { display: flex; flex-wrap: wrap; gap: 9px; }
.person-chip { padding: 8px 11px; border: 1px solid #dbe5f5; border-radius: 999px; color: #344054; background: #f8fafc; font-size: 13px; font-weight: 700; }
.warning-card { border-color: #fedf89; background: #fffdf5; }
.warning-card h3 { color: #93370d; }
.warning-card p { margin: 0; color: #7a2e0e; line-height: 1.65; }
.warning-card code { padding: 2px 5px; border-radius: 5px; background: #fff4cc; }
.save-message { min-height: 20px; margin-top: 12px; color: var(--success); font-size: 13px; }

.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.status-card { min-height: 190px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.status-card > span { display: inline-block; margin-bottom: 22px; padding: 6px 8px; border-radius: 7px; font-size: 11px; font-weight: 850; }
.status-card h3 { margin-bottom: 8px; font-size: 17px; }
.status-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.status-card.done > span { color: var(--success); background: var(--success-soft); }
.status-card.next > span { color: #175cd3; background: #eff8ff; }
.status-card.blocked > span { color: var(--warning); background: var(--warning-soft); }
.health-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 20px; margin-top: 18px; }
.health-card h3 { margin-bottom: 6px; }
.health-card p { margin: 0; color: var(--muted); }
.health-card pre { grid-column: 1 / -1; margin: 0; padding: 14px; overflow: auto; border-radius: 10px; color: #d1fadf; background: #101828; font-size: 12px; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(390px, calc(100vw - 44px)); padding: 12px 16px; border-radius: 11px; color: #fff; background: #101828; box-shadow: 0 18px 45px rgba(16,24,40,.28); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .split-layout { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
  .weekly-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; max-width: 100vw; height: auto; padding: 15px; }
  .brand-block { padding: 0 5px 14px; }
  .nav-list { display: flex; overflow-x: auto; }
  .nav-item { width: auto; flex: 0 0 auto; }
  .sidebar-foot { display: none; }
  .content { padding: 24px 15px 54px; }
  .topbar, .page-intro { align-items: flex-start; }
  .cloud-badge { display: none; }
  .form-grid, .weekly-top-grid, .settings-grid { grid-template-columns: 1fr; }
  .field.full, .settings-grid .warning-card { grid-column: auto; }
  .weekly-board, .status-grid { grid-template-columns: 1fr; }
  .card { padding: 18px; border-radius: 14px; }
  .jira-connection { align-items: flex-start; flex-direction: column; }
  .health-card { grid-template-columns: 1fr; }
  .health-card pre { grid-column: auto; }
}
