:root {
  --ink: #161716;
  --ink-soft: #545752;
  --paper: #f3f3ef;
  --surface: #ffffff;
  --line: #d9dbd5;
  --line-dark: #b8bbb4;
  --red: #f23818;
  --red-dark: #c8270d;
  --green: #157053;
  --amber: #aa6b00;
  --blue: #225c83;
  --shadow: 0 18px 60px rgba(17, 18, 17, 0.16);
  --sidebar-width: 224px;
  --topbar-height: 76px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Avenir Next", "Noto Sans TC", "PingFang TC", sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-family: "DIN Alternate", "Avenir Next Condensed", sans-serif;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.eyebrow--red { color: var(--red); }

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-lockup img {
  width: 43px;
  height: 43px;
  object-fit: cover;
  object-position: left center;
}

.brand-lockup div { display: grid; gap: 1px; min-width: 0; }
.brand-lockup strong { font-size: 15px; line-height: 1.1; white-space: nowrap; }
.brand-lockup span { color: var(--ink-soft); font-family: "DIN Alternate", sans-serif; font-size: 10px; font-weight: 700; }
.brand-lockup--light strong { color: #fff; }
.brand-lockup--light span { color: #bfc2bc; }

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 1.05fr) minmax(420px, 0.95fr);
}

.login-brand {
  position: relative;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(32px, 5vw, 76px);
  overflow: hidden;
  color: #fff;
  background: var(--ink);
}

.login-brand::before {
  content: "";
  position: absolute;
  top: -16%;
  right: -16%;
  width: 72%;
  aspect-ratio: 1;
  border: clamp(48px, 7vw, 110px) solid var(--red);
  transform: rotate(18deg);
  opacity: 0.96;
}

.login-brand::after {
  content: "AU";
  position: absolute;
  right: -18px;
  bottom: -96px;
  color: rgba(255, 255, 255, 0.045);
  font-family: "DIN Condensed", "Avenir Next Condensed", sans-serif;
  font-size: clamp(260px, 40vw, 620px);
  font-weight: 900;
  line-height: 0.8;
}

.login-brand > * { position: relative; z-index: 1; }
.login-brand__statement { max-width: 700px; margin: 12vh 0 8vh; }
.login-brand__statement .eyebrow { color: #c7cac3; }
.login-brand__statement h1 {
  max-width: 760px;
  margin: 0;
  font-family: "DIN Condensed", "Avenir Next Condensed", sans-serif;
  font-size: clamp(52px, 7vw, 106px);
  font-weight: 900;
  line-height: 0.88;
}
.login-brand__statement > p:last-child { max-width: 430px; margin: 26px 0 0; color: #d9dcd5; font-size: 18px; }
.login-brand__footer { display: flex; gap: 28px; color: #aeb1aa; font-family: "DIN Alternate", sans-serif; font-size: 11px; font-weight: 700; }

.login-panel {
  display: grid;
  place-items: center;
  min-height: 620px;
  padding: clamp(32px, 8vw, 110px);
  background-color: var(--paper);
  background-image: linear-gradient(#e2e3de 1px, transparent 1px), linear-gradient(90deg, #e2e3de 1px, transparent 1px);
  background-size: 32px 32px;
}

.login-form { width: min(100%, 430px); padding: 42px; border-top: 5px solid var(--red); background: var(--surface); box-shadow: var(--shadow); }
.login-form__heading { margin-bottom: 32px; }
.login-form__heading h2 { margin: 0; font-family: "Avenir Next Condensed", sans-serif; font-size: 34px; line-height: 1.1; }
.login-form__heading > p:last-child { margin: 10px 0 0; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }
.login-form__support { margin: 22px 0 0; color: var(--ink-soft); font-size: 12px; text-align: center; }

.field { display: grid; gap: 7px; margin-bottom: 20px; }
.field > span { color: #343633; font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea, .search-field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--ink);
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  outline: 0;
  background: #fff;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.field textarea { min-height: 92px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search-field input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(242, 56, 24, 0.12); }
.field small { min-height: 15px; color: #b6240d; font-size: 11px; }
.field.has-error input, .field.has-error select { border-color: #b6240d; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 800;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { cursor: wait; opacity: 0.58; }
.button--primary { color: #fff; background: var(--red); }
.button--primary:hover { background: var(--red-dark); }
.button--secondary { color: var(--ink); border-color: var(--line-dark); background: #fff; }
.button--secondary:hover { border-color: var(--ink); }
.button--quiet { min-height: 36px; padding: 7px 12px; color: var(--ink-soft); border-color: var(--line); background: transparent; }
.button--quiet:hover { color: var(--ink); border-color: var(--ink); }
.button--full { width: 100%; }

.form-alert { margin: 0 0 18px; padding: 10px 12px; color: #8a1e0c; border-left: 3px solid var(--red); background: #fff0ec; font-size: 13px; line-height: 1.45; }

.app-view { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: var(--topbar-height) minmax(calc(100vh - var(--topbar-height)), auto); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}
.topbar__account { display: flex; align-items: center; gap: 16px; }
.agent-badge { display: flex; align-items: center; gap: 10px; }
.agent-badge__initials { width: 34px; height: 34px; display: grid; place-items: center; color: #fff; border-radius: 50%; background: var(--ink); font-family: "DIN Alternate", sans-serif; font-size: 12px; font-weight: 800; }
.agent-badge__copy { display: grid; gap: 1px; }
.agent-badge__copy strong { font-size: 13px; }
.agent-badge__copy small { color: var(--ink-soft); font-size: 10px; }

.sidebar { position: sticky; top: var(--topbar-height); height: calc(100vh - var(--topbar-height)); display: flex; flex-direction: column; padding: 28px 16px 22px; color: #fff; background: var(--ink); }
.sidebar__region { display: grid; gap: 2px; margin: 0 10px 28px; padding-bottom: 20px; border-bottom: 1px solid #383a37; }
.sidebar__region span, .sidebar__region small { color: #9da099; font-size: 10px; }
.sidebar__region strong { margin-top: 2px; font-family: "Avenir Next Condensed", sans-serif; font-size: 22px; }
.nav-list { display: grid; gap: 5px; }
.nav-item { width: 100%; min-height: 46px; display: grid; grid-template-columns: 28px 1fr; align-items: center; padding: 8px 12px; color: #cfd2cb; border: 0; border-left: 3px solid transparent; border-radius: 2px; background: transparent; text-align: left; }
.nav-item:hover { color: #fff; background: #272927; }
.nav-item.is-active { color: #fff; border-left-color: var(--red); background: #2c2e2b; }
.nav-item__index { color: #777b75; font-family: "DIN Alternate", sans-serif; font-size: 10px; }
.sidebar__security { margin: auto 10px 0; color: #8e918b; font-size: 11px; line-height: 1.5; }

.workspace { min-width: 0; padding: clamp(30px, 4vw, 58px); }
.workspace-section { width: min(100%, 1320px); margin: 0 auto; }
.page-header, .detail-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 28px; }
.page-header h1, .detail-header h1 { margin: 0; font-family: "Avenir Next Condensed", sans-serif; font-size: clamp(38px, 4vw, 58px); line-height: 0.96; }
.page-header > div > p:last-child, .detail-header > div > p:last-child { margin: 12px 0 0; color: var(--ink-soft); font-size: 14px; }

.metrics-band { min-height: 118px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 28px; border: 1px solid var(--line); border-top: 4px solid var(--ink); background: var(--surface); }
.metric { display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 22px 28px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { color: var(--ink-soft); font-size: 12px; }
.metric strong { font-family: "DIN Alternate", "Avenir Next Condensed", sans-serif; font-size: 31px; line-height: 1; }
.metric--accent { color: #fff; background: var(--blue); }
.metric--accent span { color: #d7e5ed; }

.list-tools { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; }
.search-field { flex: 1; max-width: 560px; }
.search-field input { min-height: 44px; padding-left: 14px; background: var(--surface); }
.result-count { margin-left: auto; color: var(--ink-soft); font-size: 12px; font-weight: 700; white-space: nowrap; }

.table-wrap { overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th { height: 43px; padding: 0 15px; color: var(--ink-soft); border-bottom: 1px solid var(--line-dark); background: #e9eae6; font-size: 10px; text-align: left; text-transform: uppercase; }
.data-table td { min-height: 62px; padding: 14px 15px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background-color 120ms ease; }
.data-table tbody tr:hover { background: #fafaf7; }
.data-table th:nth-child(1) { width: 27%; }
.data-table th:nth-child(2) { width: 16%; }
.data-table th:nth-child(3) { width: 17%; }
.data-table th:nth-child(4) { width: 14%; }
.data-table th:nth-child(5) { width: 17%; }
.data-table th:nth-child(6) { width: 9%; }
.customer-name { display: grid; gap: 4px; min-width: 0; }
.customer-name strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.customer-name small { color: var(--ink-soft); font-size: 10px; }
.row-action { min-width: 64px; padding: 7px 10px; color: var(--ink); border: 1px solid var(--line); border-radius: 2px; background: transparent; font-size: 11px; font-weight: 800; }
.row-action:hover { color: #fff; border-color: var(--ink); background: var(--ink); }
.tag { display: inline-flex; min-height: 25px; align-items: center; padding: 3px 8px; border: 1px solid #c6c9c2; border-radius: 2px; color: #4b4e49; background: #f5f5f1; font-size: 10px; font-weight: 700; }
.tag--active { color: var(--green); border-color: #a9cabb; background: #eff8f4; }
.tag--warning { color: var(--amber); border-color: #d8bd86; background: #fff8e8; }
.agent-table th:nth-child(1) { width: 38%; }
.agent-table th:nth-child(2) { width: 26%; }
.agent-table th:nth-child(3) { width: 16%; }
.agent-table th:nth-child(4) { width: 20%; }
.agent-code-value { font-family: "DIN Alternate", "Avenir Next Condensed", sans-serif; font-size: 14px; }

.loading-state { min-height: 170px; display: flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); }
.loading-state span { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 900ms ease-in-out infinite; }
.loading-state span:nth-child(2) { animation-delay: 140ms; }
.loading-state span:nth-child(3) { animation-delay: 280ms; }
@keyframes pulse { 0%, 100% { transform: translateY(0); opacity: .35; } 50% { transform: translateY(-6px); opacity: 1; } }

.empty-state { min-height: 310px; display: grid; place-items: center; align-content: center; padding: 36px; border: 1px dashed var(--line-dark); background: rgba(255,255,255,.48); text-align: center; }
.empty-state h2, .empty-state h3 { margin: 0; font-family: "Avenir Next Condensed", sans-serif; font-size: 28px; }
.empty-state p:not(.eyebrow) { max-width: 520px; margin: 10px 0 20px; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }
.empty-state--compact { min-height: 180px; }
.empty-state--compact h3 { font-size: 22px; }

.text-action { margin-bottom: 28px; padding: 0 0 4px; color: var(--ink-soft); border: 0; border-bottom: 1px solid var(--line-dark); background: transparent; font-size: 12px; font-weight: 700; }
.text-action:hover { color: var(--red); border-bottom-color: var(--red); }
.detail-header { align-items: center; margin-bottom: 24px; }
.ownership-stamp { min-width: 120px; padding: 13px 16px; color: #fff; border-left: 4px solid var(--red); background: var(--ink); }
.ownership-stamp span { display: block; color: #aeb1aa; font-size: 9px; }
.ownership-stamp strong { display: block; margin-top: 3px; font-family: "DIN Alternate", sans-serif; font-size: 17px; }

.customer-facts { margin-bottom: 40px; border-top: 1px solid var(--line-dark); border-bottom: 1px solid var(--line-dark); background: var(--surface); }
.customer-facts dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; }
.customer-facts dl > div { min-height: 92px; padding: 20px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.customer-facts dl > div:nth-child(3n) { border-right: 0; }
.customer-facts dl > div:nth-last-child(-n+3) { border-bottom: 0; }
.customer-facts dt { margin-bottom: 7px; color: var(--ink-soft); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.customer-facts dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 650; }

.orders-section { margin-top: 8px; }
.section-heading { display: flex; align-items: flex-end; gap: 24px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-family: "Avenir Next Condensed", sans-serif; font-size: 28px; }
.orders-list { display: grid; gap: 12px; }
.order-row { display: grid; grid-template-columns: minmax(150px, 1.2fr) minmax(110px, .7fr) minmax(110px, .7fr) minmax(130px, .8fr) 110px; gap: 18px; align-items: center; min-height: 82px; padding: 16px 18px; border: 1px solid var(--line); border-left: 4px solid var(--ink); background: var(--surface); }
.order-row.is-complete { border-left-color: var(--green); }
.order-main { display: grid; gap: 3px; min-width: 0; }
.order-main strong { overflow: hidden; font-family: "DIN Alternate", sans-serif; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.order-main small, .order-cell span { color: var(--ink-soft); font-size: 10px; }
.order-cell { display: grid; gap: 4px; }
.order-cell strong { font-size: 12px; overflow-wrap: anywhere; }
.status-pill { min-height: 27px; display: inline-flex; align-items: center; justify-content: center; padding: 4px 9px; color: var(--blue); border: 1px solid #aac1d1; border-radius: 999px; background: #eef5f9; font-size: 10px; font-weight: 800; text-align: center; }
.status-pill.is-paid { color: var(--green); border-color: #a9cabb; background: #eff8f4; }
.order-items { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 7px; padding-top: 11px; border-top: 1px solid var(--line); }
.order-item-chip { padding: 5px 8px; color: #454743; border: 1px solid var(--line); background: #f6f6f2; font-size: 10px; }

.customer-dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 4px; box-shadow: var(--shadow); }
.customer-dialog::backdrop { background: rgba(12, 13, 12, 0.68); backdrop-filter: blur(2px); }
.customer-form { padding: 0; }
.dialog-header { min-height: 96px; display: flex; align-items: center; justify-content: space-between; padding: 24px 28px; color: #fff; border-bottom: 5px solid var(--red); background: var(--ink); }
.dialog-header h2 { margin: 0; font-family: "Avenir Next Condensed", sans-serif; font-size: 28px; }
.dialog-header .eyebrow { color: #ff765e; }
.dialog-close { width: 36px; height: 36px; padding: 0; color: #fff; border: 1px solid #5a5d57; border-radius: 50%; background: transparent; font-size: 26px; line-height: 1; }
.dialog-close:hover { border-color: #fff; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; padding: 28px 28px 8px; }
.field--wide { grid-column: 1 / -1; }
.customer-form .form-alert { margin: 0 28px 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 28px; border-top: 1px solid var(--line); background: #f2f2ee; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: min(390px, calc(100vw - 44px)); padding: 13px 16px; color: #fff; border-left: 4px solid var(--red); border-radius: 2px; background: var(--ink); box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 900px) {
  .login-view { grid-template-columns: 1fr; }
  .login-brand { min-height: 340px; padding: 30px; }
  .login-brand::before { width: 46%; border-width: 52px; }
  .login-brand::after { bottom: -60px; font-size: 270px; }
  .login-brand__statement { margin: 55px 0 20px; }
  .login-brand__statement h1 { font-size: 54px; }
  .login-brand__statement > p:last-child { margin-top: 16px; font-size: 15px; }
  .login-panel { min-height: auto; padding: 46px 22px; }
  .login-form { padding: 32px; }

  .app-view { grid-template-columns: 1fr; grid-template-rows: var(--topbar-height) auto 1fr; }
  .sidebar { position: static; grid-row: 2; height: auto; flex-direction: row; align-items: center; padding: 0 20px; background: #232522; }
  .sidebar__region, .sidebar__security { display: none; }
  .nav-list { display: flex; gap: 0; }
  .nav-item { width: auto; min-height: 46px; grid-template-columns: 1fr; padding: 8px 14px; border-left: 0; border-bottom: 3px solid transparent; }
  .nav-item.is-active { border-left: 0; border-bottom-color: var(--red); }
  .nav-item__index { display: none; }
  .workspace { grid-row: 3; }
  .customer-facts dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-facts dl > div:nth-child(3n) { border-right: 1px solid var(--line); }
  .customer-facts dl > div:nth-child(2n) { border-right: 0; }
  .customer-facts dl > div:nth-last-child(-n+3) { border-bottom: 1px solid var(--line); }
  .customer-facts dl > div:nth-last-child(-n+2) { border-bottom: 0; }
  .order-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-items { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  :root { --topbar-height: 66px; }
  .topbar { padding: 0 15px; }
  .brand-lockup img { width: 35px; height: 35px; }
  .brand-lockup strong { font-size: 12px; }
  .agent-badge__copy { display: none; }
  .agent-badge__initials { width: 36px; height: 36px; }
  .topbar__account { gap: 8px; }
  .topbar .button--quiet { min-width: 52px; padding: 6px 9px; }
  .sidebar { padding: 0 10px; overflow-x: auto; }
  .workspace { padding: 26px 16px 40px; }
  .page-header, .detail-header { align-items: flex-start; }
  .page-header h1, .detail-header h1 { font-size: 40px; }
  .page-header > .button { padding: 9px 12px; white-space: nowrap; }
  .metrics-band { min-height: 88px; }
  .metric { padding: 14px; }
  .metric span { font-size: 10px; }
  .metric strong { font-size: 22px; }
  .list-tools { align-items: stretch; flex-direction: column; gap: 8px; }
  .result-count { margin-left: 0; }
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .data-table, .data-table tbody { display: block; }
  .data-table thead { display: none; }
  .data-table tr { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; margin-bottom: 9px; padding: 16px; border: 1px solid var(--line); border-left: 4px solid var(--ink); background: var(--surface); }
  .data-table td { min-height: 0; display: block; padding: 0; border: 0; }
  .data-table td:nth-child(1) { grid-column: 1 / -1; }
  .data-table td:nth-child(2)::before { content: "聯絡人  "; color: var(--ink-soft); font-size: 9px; }
  .data-table td:nth-child(3) { grid-column: 1 / -1; color: var(--ink-soft); }
  .data-table td:nth-child(4), .data-table td:nth-child(5) { display: none; }
  .data-table td:nth-child(6) { grid-column: 2; grid-row: 2; }
  .agent-table td:nth-child(1) { grid-column: 1 / -1; }
  .agent-table td:nth-child(2) { grid-column: 1; color: var(--ink); }
  .agent-table td:nth-child(2)::before { content: "代理  "; color: var(--ink-soft); font-size: 9px; }
  .agent-table td:nth-child(3) { grid-column: 2; grid-row: 2; }
  .agent-table td:nth-child(4) { display: block; grid-column: 1 / -1; color: var(--ink-soft); font-size: 11px; }
  .agent-table td:nth-child(4)::before { content: "建立日期  "; font-size: 9px; }
  .customer-name strong { font-size: 15px; }
  .detail-header { gap: 12px; }
  .ownership-stamp { min-width: 94px; padding: 10px 12px; }
  .customer-facts dl { grid-template-columns: 1fr; }
  .customer-facts dl > div, .customer-facts dl > div:nth-child(2n), .customer-facts dl > div:nth-child(3n), .customer-facts dl > div:nth-last-child(-n+2) { min-height: 75px; border-right: 0; border-bottom: 1px solid var(--line); }
  .customer-facts dl > div:last-child { border-bottom: 0; }
  .order-row { grid-template-columns: 1fr 1fr; gap: 13px; padding: 15px; }
  .order-main { grid-column: 1 / -1; }
  .order-items { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; padding: 22px 20px 4px; }
  .field--wide { grid-column: auto; }
  .dialog-header { padding: 20px; }
  .customer-form .form-alert { margin: 0 20px 16px; }
  .dialog-actions { padding: 16px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
