:root {
  color-scheme: dark;
  --bg: #11161f;
  --surface: #1a212c;
  --surface-2: #222b38;
  --border: #303b4a;
  --text: #edf3fc;
  --muted: #93a1b5;
  --blue: #66a4ff;
  --blue-strong: #4388ef;
  --gold: #f5b84c;
  --green: #5fd0a1;
  --danger: #ff8b8b;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.topbar { height: 60px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: #171d26; }
.brand { color: var(--blue); font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.brand span { margin-left: 7px; padding: 3px 7px; border: 1px solid #3b5270; border-radius: 99px; color: var(--muted); font-size: 10px; }
.account { color: #cbd5e3; font-size: 14px; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px #5fd0a118; }
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.sidebar { padding: 32px 20px; border-right: 1px solid var(--border); background: #151b24; }
.eyebrow { margin: 0 0 9px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a { padding: 11px 13px; border-radius: 9px; color: var(--muted); text-decoration: none; font-size: 14px; }
.sidebar nav a.active { background: #26374d; color: #dcecff; }
.mission { margin-top: 40px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(145deg, #202a38, #19212c); display: grid; gap: 7px; }
.mission span, .mission small { color: var(--muted); font-size: 12px; }
.mission div { height: 5px; overflow: hidden; border-radius: 99px; background: #313d4d; }
.mission i { display: block; height: 100%; border-radius: inherit; background: var(--blue); }
.content { width: min(1180px, 100%); margin: 0 auto; padding: 42px 44px 80px; }
.heading-row { display: flex; justify-content: space-between; gap: 24px; align-items: end; }
h1 { margin: 0; font-size: clamp(28px, 3vw, 40px); letter-spacing: -.03em; }
.subtitle { margin: 10px 0 0; color: var(--muted); }
.secondary, .primary, .text-button { border: 0; border-radius: 9px; }
.secondary { padding: 10px 15px; border: 1px solid #486996; background: transparent; color: var(--blue); }
.primary { padding: 13px 22px; background: var(--blue-strong); color: white; font-weight: 800; box-shadow: 0 8px 24px #4388ef33; }
.text-button { background: transparent; color: var(--blue); }
.mode-switch { display: inline-flex; margin: 30px 0 22px; padding: 4px; border-radius: 10px; background: #0d1219; }
.mode-switch button { padding: 9px 17px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); }
.mode-switch button.selected { background: var(--surface-2); color: var(--text); }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; }
.steps span { position: relative; display: flex; gap: 8px; align-items: center; padding-bottom: 15px; color: #657389; font-size: 12px; }
.steps span::after { content: ""; position: absolute; left: 0; right: 6px; bottom: 0; height: 3px; border-radius: 99px; background: #27313e; }
.steps span.done, .steps span.current { color: var(--blue); }
.steps span.done::after, .steps span.current::after { background: var(--blue); }
.panel { margin-top: 15px; padding: 24px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel-title > div { display: flex; align-items: center; gap: 11px; }
.panel-title h2 { margin: 0; font-size: 17px; }
.number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: #263b59; color: var(--blue); font-size: 12px; font-weight: 800; }
.number.success { background: #1f473c; color: var(--green); }
.hint { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 15px; }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
label em { margin-left: 5px; color: var(--blue); font-size: 10px; font-style: normal; font-weight: 700; }
.switch-row { min-height: 43px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); }
.switch-row input { width: 17px; height: 17px; padding: 0; accent-color: var(--blue-strong); }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; outline: 0; background: var(--surface-2); color: var(--text); }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #66a4ff1a; }
.item-card { padding: 20px; border: 1px solid #354356; border-radius: 12px; background: #1d2632; }
.item-card + .item-card { margin-top: 14px; }
.item-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.item-heading h3 { margin: 0; font-size: 14px; }
.remove-item { border: 0; background: transparent; color: var(--danger); font-size: 12px; }
.cost-grid { margin-top: 15px; }
.process-cost-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.subheading { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.subheading strong { font-size: 13px; }
.subheading span { color: var(--muted); font-size: 11px; }
.process-cost-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.process-cost-card { padding: 14px; border: 1px solid #324155; border-radius: 10px; background: #19222e; }
.process-cost-card h4 { margin: 0 0 11px; color: #dce8f8; font-size: 13px; }
.process-cost-fields { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 10px; align-items: start; }
.process-cost-fields.three { grid-template-columns: minmax(0, 1.2fr) repeat(2, minmax(0, .8fr)); }
.paper-card, .die-card, .shared-cost-card { grid-column: 1 / -1; }
.process-assignment { align-content: start; }
.process-assignment input { margin-top: 1px; }
.reminder { margin: 15px 0 0; padding: 10px 12px; border-radius: 8px; background: #f5b84c0d; color: #d6ba85; font-size: 12px; }
.fsc-reminder { margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; background: #66a4ff0d; color: #a9cfff; font-size: 12px; }
.actions { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.action-buttons { display: flex; align-items: center; gap: 10px; }
#form-message { color: var(--muted); font-size: 13px; }
.hidden { display: none; }
.badge { padding: 6px 10px; border-radius: 99px; font-size: 12px; }
.badge.approved { background: #1e493c; color: var(--green); }
.badge.warning { background: #59401d; color: #ffd384; }
.result-row { display: grid; grid-template-columns: 1.7fr repeat(5, 1fr); gap: 16px; align-items: center; padding: 18px 0; border-bottom: 1px solid var(--border); }
.result-row > div { display: grid; gap: 6px; }
.result-row span, .summary span { color: var(--muted); font-size: 12px; }
.result-row .accent { color: var(--gold); }
.result-costs { grid-column: 1 / -1; display: flex !important; flex-wrap: wrap; gap: 7px !important; padding-top: 3px; }
.result-costs span { padding: 5px 8px; border: 1px solid #344255; border-radius: 6px; background: #18212c; color: #aebbd0; font-size: 11px; }
[data-cost-preview] { display: block; margin-top: 6px; color: #8fa8c8; font-size: 11px; line-height: 1.45; }
.summary { display: flex; justify-content: flex-end; gap: 42px; margin-top: 20px; }
.summary > div { display: grid; gap: 7px; }
.summary .total strong { color: var(--gold); font-size: 22px; }
.work-order-panel { display: grid; grid-template-columns: minmax(260px, 1.4fr) minmax(150px, .6fr) 1fr 1.3fr auto; gap: 14px; align-items: end; margin-top: 24px; padding: 18px; border: 1px solid #3a4c63; border-radius: 11px; background: #151e29; }
.work-order-panel > div { display: grid; gap: 6px; }
.work-order-panel > div span, #work-order-message { color: var(--muted); font-size: 11px; }
.check-row { min-height: 43px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); line-height: 1.35; }
.check-row input { width: 16px; min-width: 16px; padding: 0; accent-color: var(--blue-strong); }
#work-order-message { grid-column: 1 / -1; }

.nav-icon { display: inline-block; width: 18px; color: var(--blue); }
.knowledge-heading { align-items: center; }
.knowledge-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; margin: 28px 0 16px; }
.knowledge-stats article { display: flex; align-items: center; gap: 13px; padding: 17px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.knowledge-stats article > div { display: grid; gap: 2px; }
.knowledge-stats strong { font-size: 20px; }
.knowledge-stats article span:last-child { color: var(--muted); font-size: 11px; }
.stat-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; font-weight: 900; }
.stat-icon.blue { background: #4388ef1b; color: var(--blue); }
.stat-icon.red { background: #ff8b8b18; color: var(--danger); }
.stat-icon.green { background: #5fd0a118; color: var(--green); }
.stat-icon.gold { background: #f5b84c18; color: var(--gold); }
.knowledge-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, .8fr); gap: 16px; align-items: start; }
.library-panel, .chat-panel { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
.library-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 20px 14px; }
.library-toolbar > div:first-child { display: flex; align-items: baseline; gap: 9px; }
.library-toolbar h2 { margin: 0; font-size: 17px; }
.library-toolbar > div span { color: var(--muted); font-size: 11px; }
.knowledge-search { position: relative; display: block; width: min(330px, 58%); }
.knowledge-search > span { position: absolute; z-index: 1; left: 12px; top: 10px; color: var(--muted); font-size: 16px; }
.knowledge-search input { padding-left: 35px; background: #151c26; }
.knowledge-filters { display: flex; align-items: center; gap: 7px; padding: 0 20px 15px; border-bottom: 1px solid var(--border); }
.knowledge-filters select { width: auto; min-width: 120px; margin-left: auto; padding: 7px 10px; font-size: 11px; }
.filter-chip { padding: 7px 11px; border: 1px solid transparent; border-radius: 99px; background: transparent; color: var(--muted); font-size: 11px; }
.filter-chip.selected { border-color: #466992; background: #26374d; color: #dcecff; }
.knowledge-list { min-height: 490px; }
.knowledge-card { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.knowledge-card:last-child { border-bottom: 0; }
.knowledge-card:hover { background: #1e2733; }
.knowledge-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.knowledge-card-title { display: flex; gap: 11px; align-items: flex-start; }
.knowledge-kind { flex: 0 0 auto; display: grid; place-items: center; width: 31px; height: 31px; border-radius: 8px; background: #4388ef18; color: var(--blue); font-size: 12px; font-weight: 900; }
.knowledge-kind.incident { background: #ff8b8b13; color: var(--danger); }
.knowledge-card h3 { margin: 0 0 5px; font-size: 14px; }
.knowledge-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: 10px; }
.knowledge-summary { margin: 11px 0 0 42px; color: #b7c3d4; font-size: 12px; line-height: 1.65; }
.knowledge-card details { margin: 10px 0 0 42px; }
.knowledge-card summary { width: max-content; color: var(--blue); cursor: pointer; font-size: 11px; }
.knowledge-details { display: grid; gap: 9px; margin-top: 12px; padding: 12px; border-radius: 8px; background: #151d27; color: #b8c5d8; font-size: 11px; line-height: 1.65; }
.knowledge-details strong { color: #dce5f3; }
.knowledge-tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 11px 0 0 42px; }
.knowledge-tags span { padding: 3px 7px; border-radius: 5px; background: #293544; color: #9fadc1; font-size: 9px; }
.severity { padding: 4px 8px; border-radius: 99px; white-space: nowrap; color: var(--muted); background: #2a3442; font-size: 9px; }
.severity.high, .severity.critical { color: #ffaaaa; background: #572c32; }
.severity.medium { color: #ffd084; background: #514022; }
.knowledge-empty { min-height: 440px; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.knowledge-empty > span { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: 15px; background: #26374d; color: var(--blue); font-size: 21px; }
.knowledge-empty p { max-width: 330px; margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.chat-panel { position: sticky; top: 16px; }
.chat-header { min-height: 70px; display: flex; align-items: center; gap: 11px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.assistant-avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(145deg, #3a81e6, #775bd9); color: white; box-shadow: 0 7px 20px #4388ef2b; }
.chat-header > div:nth-child(2) { display: grid; gap: 4px; }
.chat-header > div span { color: var(--muted); font-size: 10px; }
.chat-header i { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: var(--green); }
.chat-header > button { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.chat-messages { height: 431px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; padding: 18px 15px; background: #151c25; }
.chat-message { display: flex; gap: 8px; align-items: flex-start; }
.chat-message.user { justify-content: flex-end; }
.mini-avatar { flex: 0 0 auto; display: grid; place-items: center; width: 25px; height: 25px; border-radius: 8px; background: #35496b; color: #b9d6ff; font-size: 10px; }
.bubble { max-width: calc(100% - 33px); padding: 11px 12px; border: 1px solid #334052; border-radius: 4px 12px 12px; background: #202a37; }
.user .bubble { border-color: #3c6da6; border-radius: 12px 4px 12px 12px; background: #275388; color: white; }
.bubble p { margin: 0; white-space: pre-wrap; font-size: 12px; line-height: 1.65; }
.bubble small { display: block; margin-top: 10px; color: var(--muted); font-size: 9px; }
.prompt-chips { display: grid; gap: 6px; margin-top: 8px; }
.prompt-chips button, .chat-sources button { padding: 7px 9px; border: 1px solid #40516a; border-radius: 7px; background: #18212c; color: #accaf4; text-align: left; font-size: 10px; }
.chat-sources { display: grid; gap: 6px; margin-top: 10px; padding-top: 9px; border-top: 1px solid #354153; }
.chat-sources span { color: var(--muted); font-size: 9px; }
.chat-form { padding: 12px 14px 9px; border-top: 1px solid var(--border); }
.chat-form label { display: block; }
.chat-form textarea { min-height: 58px; padding: 7px 9px; border: 0; background: transparent; }
.chat-form textarea:focus { box-shadow: none; }
.chat-form > div { display: flex; align-items: center; justify-content: space-between; }
.chat-form > div span { color: #68768b; font-size: 9px; }
.chat-form button { display: grid; place-items: center; width: 31px; height: 31px; border: 0; border-radius: 8px; background: var(--blue-strong); color: white; }
.chat-notice { margin: 0; padding: 0 14px 12px; color: #68768b; font-size: 9px; }

.knowledge-dialog { width: min(820px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid #3a4658; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 25px 80px #0009; }
.knowledge-dialog::backdrop { background: #080b10cc; backdrop-filter: blur(4px); }
.dialog-shell { padding: 24px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-header .eyebrow { margin-bottom: 5px; }
.dialog-header h2 { margin: 0; }
.dialog-close { border: 0; background: transparent; color: var(--muted); font-size: 25px; }
.dialog-intro { margin: 8px 0 17px; color: var(--muted); font-size: 12px; }
.upload-drop { position: relative; display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 14px; border: 1px dashed #4a5a70; border-radius: 10px; background: #151d27; }
.upload-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: #263b59; color: var(--blue); font-size: 19px; }
.upload-drop > div { display: grid; gap: 3px; }
.upload-drop > div span { color: var(--muted); font-size: 10px; }
.upload-drop button { margin-left: auto; padding: 8px 12px; }
.form-three { grid-template-columns: 1fr 1fr 1fr; }
.form-two { grid-template-columns: 1fr 1fr; margin-top: 14px; }
.dialog-shell > label { margin-top: 14px; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 20px; padding-top: 17px; border-top: 1px solid var(--border); }
.dialog-actions span { margin-right: auto; color: var(--muted); font-size: 11px; }
.dialog-actions .secondary { padding: 12px 18px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 28px 20px 60px; }
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-row { grid-template-columns: 1fr 1fr; }
  .result-row > div:first-child { grid-column: 1 / -1; }
  .work-order-panel { grid-template-columns: 1fr 1fr; }
  .work-order-panel > div, #work-order-message { grid-column: 1 / -1; }
  .process-cost-grid { grid-template-columns: 1fr; }
  .paper-card, .die-card, .shared-cost-card { grid-column: auto; }
  .knowledge-stats { grid-template-columns: repeat(2, 1fr); }
  .knowledge-layout { grid-template-columns: 1fr; }
  .chat-panel { position: static; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 16px; }
  .heading-row { align-items: start; flex-direction: column; }
  .grid.four { grid-template-columns: 1fr; }
  .steps b { display: none; }
  .panel { padding: 18px; }
  .summary { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .summary .total { grid-column: 1 / -1; }
  .work-order-panel { grid-template-columns: 1fr; }
  .work-order-panel > * { grid-column: 1 / -1; }
  .process-cost-fields, .process-cost-fields.three { grid-template-columns: 1fr; }
  .knowledge-stats { grid-template-columns: 1fr 1fr; }
  .knowledge-stats article { padding: 13px; }
  .library-toolbar { align-items: stretch; flex-direction: column; }
  .knowledge-search { width: 100%; }
  .knowledge-filters { flex-wrap: wrap; }
  .knowledge-filters select { width: 100%; margin: 4px 0 0; }
  .form-three, .form-two { grid-template-columns: 1fr; }
  .upload-drop { align-items: flex-start; flex-wrap: wrap; }
  .upload-drop button { width: 100%; margin-left: 0; }
  .dialog-shell { padding: 18px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions span { width: 100%; }
}
