/* Aventa 客服（CS1）樣式。
   設計方向：這是整天開著的工作工具，畫面安靜、字清楚。
   唯一醒目的東西是「入口的主色」：系統管理後台＝藍染，商家後台＝松葉綠，登入頁與功能列整面用它，兩套後台一眼分得出來。
   目前所在頁用山吹黃一條線標示；其他地方不用裝飾。 */

:root {
  --paper: #f3f5f7;
  --surface: #ffffff;
  --ink: #17202a;
  --ink-soft: #55616e;
  --line: #d5dbe2;
  --marker: #e5ae2e;
  --entrance: #1f3f5c;
  --entrance-deep: #17304a;
  --font: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}

html[data-entrance="merchant"] {
  --entrance: #1d5947;
  --entrance-deep: #154536;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font);
  font-size: 100%;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
}

h1,
h2,
p,
ul,
table {
  margin: 0;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.3;
  font-weight: 700;
}

h2 {
  font-size: 1.125rem;
  line-height: 1.4;
  font-weight: 700;
}

a {
  color: var(--entrance);
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: 3px solid var(--marker);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -999rem;
}

.skip:focus {
  left: 1rem;
  top: 1rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  background: var(--surface);
}

/* ---------- 按鈕 ---------- */

.btn-quiet {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  text-decoration: none;
  cursor: pointer;
}

.btn-quiet:hover {
  border-color: var(--ink-soft);
}

/* ---------- 登入後：功能列＋內容 ---------- */

.shell {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
}

.rail {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  color: #ffffff;
  background: var(--entrance);
}

.brand {
  display: block;
  padding: 1.5rem 1.25rem 1.25rem;
  color: inherit;
  text-decoration: none;
}

.brand-product {
  display: block;
  font-size: 0.875rem;
  opacity: 0.8;
}

.brand-entrance {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
}

/* 窄螢幕才用得到的「展開功能列」開關；寬螢幕功能列一直都在 */
.rail-toggle,
.rail-toggle-label {
  display: none;
}

.rail nav {
  flex: 1;
  padding-bottom: 1rem;
}

.rail ul {
  list-style: none;
  padding: 0;
}

.nav-group + .nav-group {
  margin-top: 1rem;
}

.nav-group-label {
  padding: 0 1.25rem 0.25rem;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.72);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.25rem;
  border-left: 4px solid transparent;
  color: #ffffff;
  text-decoration: none;
}

a.nav-item:hover {
  background: var(--entrance-deep);
}

a.nav-item[aria-current="page"] {
  border-left-color: var(--marker);
  background: var(--entrance-deep);
  font-weight: 700;
}

.nav-item.is-closed {
  color: rgba(255, 255, 255, 0.7);
  cursor: not-allowed;
}

.nav-icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
}

.nav-label {
  flex: 1;
  min-width: 0;
}

.nav-tag {
  flex: none;
  font-size: 0.75rem;
}

.who {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.who-name {
  font-weight: 700;
}

.who-meta {
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.8);
}

.who-email {
  overflow-wrap: anywhere;
}

.who form {
  margin-top: 0.75rem;
}

main {
  padding: 2.5rem 3rem 4rem;
  max-width: 62rem;
}

main:focus {
  outline: none;
}

.page-head {
  margin-bottom: 2rem;
}

.page-lead {
  margin-top: 0.5rem;
  max-width: 40em;
  color: var(--ink-soft);
}

main section + section {
  margin-top: 2.5rem;
}

main h2 {
  margin-bottom: 0.75rem;
}

.section-note {
  margin-bottom: 0.75rem;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.plain-list {
  padding-left: 1.25rem;
  max-width: 40em;
}

.feature-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
}

.feature-table th,
.feature-table td {
  padding: 0.7rem 1rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.feature-table thead th {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--ink-soft);
  background: var(--paper);
}

.feature-table tbody th {
  font-weight: 700;
  white-space: nowrap;
}

.feature-table tbody tr:last-child th,
.feature-table tbody tr:last-child td {
  border-bottom: 0;
}

.state {
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.state-open {
  color: var(--entrance);
  font-weight: 700;
}

.error-block {
  max-width: 34em;
}

.error-block p {
  margin-top: 0.75rem;
}

/* ---------- 登入前 ---------- */

.bare {
  display: grid;
  background: var(--surface);
}

.bare > .error-block {
  padding: 4rem 2rem;
  margin: 0 auto;
}

.login {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
  min-height: 100vh;
}

.login-identity {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 3rem 3.5rem 4rem;
  color: #ffffff;
  background: var(--entrance);
  border-right: 8px solid var(--marker);
}

.login-product {
  font-size: 1.125rem;
  opacity: 0.85;
}

.login-identity h1 {
  font-size: clamp(2.25rem, 5vw, 3.75rem);
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.login-audience {
  margin-top: 1.25rem;
  max-width: 26em;
  color: rgba(255, 255, 255, 0.88);
}

.login-action {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.25rem;
  padding: 3rem 3.5rem;
  max-width: 30rem;
}

.login-action h2 {
  font-size: 1.5rem;
}

.login-buttons {
  display: grid;
  gap: 0.75rem;
}

.btn-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 3rem;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 0.375rem;
  text-decoration: none;
}

.btn-google {
  color: #1f1f1f;
  background: #ffffff;
  border: 1px solid #747775;
}

.btn-google:hover {
  background: #f3f5f7;
}

/* LINE 綠底配白字對比不夠，所以兩顆登入鈕都用白底深字，LINE 用綠色小標辨識 */
.btn-line {
  color: #1f1f1f;
  background: #ffffff;
  border: 1px solid #747775;
}

.btn-line:hover {
  background: #f3f5f7;
}

.mark-line {
  flex: none;
  padding: 0.1rem 0.3rem;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: #ffffff;
  background: #058a3c;
  border-radius: 0.3rem;
}

.mark {
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
}

.login-help {
  font-size: 0.875rem;
  color: var(--ink-soft);
}

/* 登入失敗：整塊紅框放在最上面，先講發生什麼，再講怎麼辦 */
.alert {
  padding: 1rem 1.25rem;
  color: #55160c;
  background: #fef3f2;
  border: 1px solid #f0b4ac;
  border-left: 6px solid #b42318;
  border-radius: 0.375rem;
}

.alert p + p {
  margin-top: 0.4rem;
}

.alert-kicker {
  font-size: 0.875rem;
  font-weight: 700;
  color: #b42318;
}

.alert-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
}

.alert-account {
  overflow-wrap: anywhere;
}

.alert-next {
  font-weight: 700;
}

.notice {
  padding: 0.75rem 1rem;
  background: var(--paper);
  border-left: 4px solid var(--marker);
}

.notice-strong {
  border: 1px solid var(--marker);
  border-left-width: 4px;
}

.copy-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.copy-row input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.375rem;
}

/* ---------- 窄螢幕 ---------- */

@media (max-width: 48rem) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: static;
    height: auto;
    min-height: 0;
  }

  .rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .brand {
    padding: 0.75rem 1.25rem;
  }

  .rail-toggle {
    display: block;
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .rail-toggle-label {
    display: block;
    margin-right: 1.25rem;
    padding: 0.35rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 0.375rem;
    cursor: pointer;
  }

  .rail-toggle:focus-visible + .rail-toggle-label {
    outline: 3px solid var(--marker);
    outline-offset: 2px;
  }

  .rail-toggle:checked + .rail-toggle-label {
    background: var(--entrance-deep);
  }

  .rail nav,
  .rail .who {
    grid-column: 1 / -1;
  }

  .rail-toggle:not(:checked) ~ nav,
  .rail-toggle:not(:checked) ~ .who {
    display: none;
  }

  main {
    padding: 1.5rem 1.25rem 3rem;
  }

  .feature-table thead {
    display: none;
  }

  .feature-table tr {
    display: block;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--line);
  }

  .feature-table th,
  .feature-table td {
    display: block;
    padding: 0.1rem 1rem;
    border-bottom: 0;
  }

  .login {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
  }

  .login-identity {
    padding: 2.5rem 1.5rem 2rem;
    border-right: 0;
    border-bottom: 8px solid var(--marker);
  }

  .login-action {
    justify-content: flex-start;
    padding: 2rem 1.5rem 3rem;
  }
}

/* ================= 第 2 步：設定頁（列表與表單） ================= */

.page-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
}

.crumb {
  margin-bottom: 0.25rem;
  font-size: 0.9375rem;
}

.btn-primary {
  display: inline-block;
  flex: none;
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 700;
  color: #ffffff;
  background: var(--entrance);
  border: 1px solid var(--entrance);
  border-radius: 0.375rem;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--entrance-deep);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.saved {
  margin-bottom: 1rem;
  padding: 0.6rem 1rem;
  background: #eef7f1;
  border-left: 4px solid #1f7a4d;
}

.empty {
  padding: 1.5rem;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.7rem 1rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.data-table thead th {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--ink-soft);
  background: var(--paper);
  white-space: nowrap;
}

.data-table tbody th {
  font-weight: 700;
}

.data-table tbody tr:last-child th,
.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tr.is-muted th,
.data-table tr.is-muted td {
  color: var(--ink-soft);
}

.state-off {
  color: #8a5a00;
}

.tag {
  margin-left: 0.5rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  white-space: nowrap;
}

.form {
  max-width: 36rem;
}

.field {
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
}

.field-label {
  display: block;
  margin-bottom: 0.3rem;
  padding: 0;
  font-weight: 700;
}

.req {
  margin-left: 0.5rem;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.field input[type="text"],
.field input[type="email"],
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #8b96a3;
  border-radius: 0.375rem;
}

.field input[readonly],
.field select:disabled {
  background: var(--paper);
}

.field.has-error input,
.field.has-error select {
  border-color: #b42318;
  border-width: 2px;
}

.field-hint {
  margin-top: 0.3rem;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.field-error {
  margin-top: 0.3rem;
  font-weight: 700;
  color: #b42318;
}

.field-static {
  color: var(--ink-soft);
}

.field-check label,
.check-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.check-row {
  padding: 0.15rem 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

main > .alert {
  max-width: 36rem;
  margin-bottom: 1.5rem;
}

/* 功能列：目前公司、未讀數 */

.company {
  padding: 0 1.25rem 1rem;
}

.company-label {
  display: block;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.72);
}

.company-name {
  font-weight: 700;
}

.company-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.company-row select {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0.4rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: #ffffff;
  border: 0;
  border-radius: 0.3rem;
}

.btn-rail {
  flex: none;
  padding: 0.3rem 0.6rem;
  font: inherit;
  font-size: 0.875rem;
  color: #ffffff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 0.3rem;
  cursor: pointer;
}

.nav-badge,
.unread {
  flex: none;
  min-width: 1.4rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4rem;
  text-align: center;
  color: #17202a;
  background: var(--marker);
  border-radius: 0.7rem;
}

/* ================= 第 3 步：聊天頁 ================= */

.main-wide {
  max-width: none;
  padding: 0;
}

.chat {
  display: grid;
  grid-template-columns: 21rem minmax(0, 1fr);
  height: 100vh;
}

/* 聊天頁的兩欄緊貼，不套用一般頁面「區塊之間留白」的規則 */
.chat > section + section {
  margin-top: 0;
}

.chat-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.chat-list-head {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.chat-list-head h1 {
  font-size: 1.375rem;
}

.chat-live {
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

#chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.chat-items {
  list-style: none;
  padding: 0;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-left: 4px solid transparent;
  border-bottom: 1px solid var(--paper);
  color: var(--ink);
  text-decoration: none;
}

.chat-item:hover {
  background: var(--paper);
}

.chat-item[aria-current="true"] {
  background: var(--paper);
  border-left-color: var(--marker);
}

.avatar {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  background: var(--line);
}

.avatar-blank {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #ffffff;
  background: var(--entrance);
}

.chat-item-main {
  flex: 1;
  min-width: 0;
}

.chat-item-top,
.chat-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.chat-item-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-time {
  flex: none;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.chat-item-preview {
  font-size: 0.875rem;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-empty {
  padding: 1.5rem 1.25rem;
  color: var(--ink-soft);
}

.chat-thread {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #e9edf1;
}

.thread-blank {
  display: grid;
  place-items: center;
  flex: 1;
  color: var(--ink-soft);
}

.thread-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.thread-head h2 {
  margin: 0;
}

.thread-sub {
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.thread-back {
  display: none;
}

.thread-messages {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 1rem 1.5rem;
  list-style: none;
  overflow-y: auto;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.msg-out {
  flex-direction: row-reverse;
}

.bubble {
  max-width: min(34rem, 75%);
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border-radius: 0.25rem 0.9rem 0.9rem 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-out .bubble {
  color: #ffffff;
  background: var(--entrance);
  border-radius: 0.9rem 0.25rem 0.9rem 0.9rem;
}

.bubble-note {
  color: var(--ink-soft);
  border: 1px dashed #aab4bf;
  background: transparent;
}

.bubble-hint {
  display: block;
  font-size: 0.8125rem;
}

.msg time {
  flex: none;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.msg-day,
.msg-system {
  margin: 0.9rem 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.msg-day span {
  padding: 0.15rem 0.7rem;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 0.7rem;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  padding: 0.5rem 0.7rem;
  font: inherit;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  background: var(--paper);
}

@media (max-width: 48rem) {
  .page-head-row {
    flex-direction: column;
    gap: 0.75rem;
  }

  .col-minor {
    display: none;
  }

  .company {
    grid-column: 1 / -1;
  }

  .rail-toggle:not(:checked) ~ .company {
    display: none;
  }

  .chat {
    grid-template-columns: minmax(0, 1fr);
    height: calc(100vh - 3.75rem);
  }

  .chat.has-thread .chat-list,
  .chat:not(.has-thread) .chat-thread {
    display: none;
  }

  .thread-back {
    display: inline-block;
    flex: none;
    font-size: 0.9375rem;
  }

  .thread-head,
  .thread-messages,
  .composer {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
