/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1a56a0;
  --primary-light: #e8f0fb;
  --primary-hover: #154490;
  --danger: #c0392b;
  --success: #27ae60;
  --text: #2c3e50;
  --text-muted: #6b7a8d;
  --border: #d5dde8;
  --bg: #f0f4f9;
  --white: #ffffff;
  --card-shadow: 0 2px 16px rgba(26, 86, 160, 0.08);
  --radius: 10px;
}

body {
  font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Header ===== */
.site-header {
  background: var(--white);
  border-bottom: 3px solid var(--primary);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.header-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-logo {
  text-decoration: none;
  display: flex;
  align-items: center;
}

.header-logo {
  height: 48px;
  width: auto;
  display: block;
}

.header-nav {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.nav-btn {
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.nav-btn.outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}

.nav-btn.outline:hover {
  background: var(--primary-light);
}

.nav-btn.solid {
  background: var(--primary);
  color: var(--white);
}

.nav-btn.solid:hover {
  background: var(--primary-hover);
}

/* ===== Page Layout ===== */
.page-container {
  max-width: 780px;
  margin: 40px auto;
  padding: 0 20px 60px;
}

/* ===== Notice Box ===== */
.notice-box {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 28px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.notice-box p {
  margin-bottom: 4px;
}

.notice-box a {
  color: var(--primary);
  font-weight: 500;
}

/* ===== Card ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 32px 36px;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 28px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--primary-light);
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 22px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

label .required {
  color: var(--danger);
  margin-left: 3px;
}

label .hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: 6px;
}

/* password 原本不在這份清單裡，登入頁、帳號管理、變更密碼三頁的密碼欄
   一直是瀏覽器預設外觀，跟旁邊的帳號欄寬度對不齊。
   date／number／time 目前也還沒納入，要改的話一併處理。 */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 160, 0.1);
}

input.error,
select.error,
textarea.error {
  border-color: var(--danger);
}

textarea {
  resize: vertical;
  min-height: 130px;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7a8d' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.char-counter {
  text-align: right;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.char-counter.over {
  color: var(--danger);
  font-weight: 600;
}

.field-error {
  font-size: 0.78rem;
  color: var(--danger);
  margin-top: 4px;
  display: none;
}

.field-error.show {
  display: block;
}

/* ===== File Upload ===== */
.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.file-upload-area:hover,
.file-upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.file-upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  display: block;
}

.upload-text {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.upload-text strong {
  color: var(--primary);
}

.file-info {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.file-selected {
  display: none;
  margin-top: 10px;
}

.file-selected.show {
  display: block;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--primary-light);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 500;
  margin-bottom: 6px;
}

.file-list-item:last-child {
  margin-bottom: 0;
}

.file-remove-item {
  margin-left: auto;
  cursor: pointer;
  color: var(--danger);
  background: none;
  border: none;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}

.file-remove-item:hover {
  color: #7f1d1d;
}

/* ===== Submit ===== */
.submit-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 8px;
  letter-spacing: 0.5px;
}

.submit-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.submit-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.submit-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* ===== Success Screen ===== */
.success-screen {
  display: none;
  text-align: center;
  padding: 40px 20px;
}

.success-screen.show {
  display: block;
}

.success-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.success-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 12px;
}

.success-ticket {
  display: inline-block;
  background: var(--primary-light);
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  padding: 12px 28px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
  margin: 16px 0;
}

.success-msg {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.8;
  margin-bottom: 28px;
}

.success-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== Query Page ===== */
.query-result {
  display: none;
  margin-top: 24px;
}

.query-result.show {
  display: block;
}

.ticket-status-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ticket-status-header {
  background: var(--primary);
  color: var(--white);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ticket-status-body {
  padding: 20px;
}

.ticket-field {
  display: flex;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.ticket-field:last-child {
  border-bottom: none;
}

.ticket-label {
  width: 130px;
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text-muted);
}

.ticket-value {
  color: var(--text);
}

.status-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-badge.pending {
  background: #fef3c7;
  color: #92400e;
}

.status-badge.processing {
  background: #dbeafe;
  color: #1e40af;
}

.status-badge.done {
  background: #d1fae5;
  color: #065f46;
}

/* ===== Loading ===== */
.loading-spinner {
  display: none;
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
}

.loading-spinner.show {
  display: block;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 28px;
  right: 24px;
  background: var(--text);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 999;
  max-width: 320px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

/* ===== Chat ===== */
.chat-section {
  margin-top: 28px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.chat-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auto-refresh-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.refresh-btn {
  padding: 5px 12px;
  font-size: 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.refresh-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.chat-window {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafd;
  min-height: 260px;
  max-height: 420px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* 訊息氣泡 */
.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.msg-row.customer {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.engineer {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-sender {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 3px;
  color: var(--text-muted);
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row.customer .msg-bubble {
  background: #dbeafe;
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.msg-row.engineer .msg-bubble {
  background: var(--white);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* 輸入框 */
.chat-input-area {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-area textarea {
  flex: 1;
  min-height: 60px;
  max-height: 120px;
  resize: vertical;
  border-radius: 10px;
  font-size: 0.875rem;
  padding: 10px 14px;
}

.send-btn {
  padding: 10px 20px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
  height: 60px;
}

.send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ===== 評分區塊 ===== */
.rating-section {
  margin-top: 20px;
}

.rating-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 22px 24px;
}

.rating-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}

.rating-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.6;
}

.rating-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.rating-label {
  width: 80px;
  flex-shrink: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.star-group {
  display: flex;
  gap: 6px;
}

.star {
  font-size: 1.6rem;
  cursor: pointer;
  color: #d1d5db;
  transition: color 0.1s, transform 0.1s;
  line-height: 1;
  user-select: none;
}

.star:hover { transform: scale(1.15); }

.rating-comment {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  min-height: 72px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.rating-comment:focus { border-color: var(--primary); }

.rating-done {
  text-align: center;
  padding: 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #065f46;
  background: #d1fae5;
  border-radius: 8px;
}

/* ===== Site Footer ===== */
.site-footer {
  background: #1a2e4a;
  color: rgba(255,255,255,0.7);
  padding: 24px 20px;
  margin-top: 40px;
  font-size: 0.85rem;
}
.site-footer .footer-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.site-footer .footer-links {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.site-footer .footer-links a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  transition: color 0.15s;
}
.site-footer .footer-links a:hover { color: #fff; text-decoration: underline; }
.site-footer .footer-copy { color: rgba(255,255,255,0.55); font-size: 0.8rem; }

/* ===== Legal/Doc pages ===== */
.doc-page { max-width: 780px; margin: 30px auto; padding: 0 20px; }
.doc-page h1 { font-size: 1.6rem; color: #1a2e4a; margin-bottom: 6px; }
.doc-page .doc-meta { color: #6b7a8d; font-size: 0.85rem; margin-bottom: 20px; }
.doc-page h2 { font-size: 1.15rem; color: #1a56a0; margin: 22px 0 8px; padding-top: 12px; border-top: 1px solid #e6ecf3; }
.doc-page h2:first-of-type { border-top: none; padding-top: 0; }
.doc-page p, .doc-page li { font-size: 0.92rem; line-height: 1.75; color: #2c3e50; }
.doc-page ul, .doc-page ol { padding-left: 22px; margin: 6px 0 12px; }
.doc-page .faq-q { font-weight: 700; color: #1a56a0; margin-top: 16px; }
.doc-page .faq-a { color: #2c3e50; margin-top: 4px; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .site-footer .footer-inner { flex-direction: column; text-align: center; }
  .card {
    padding: 24px 18px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .page-container {
    margin: 20px auto;
  }

  .header-inner {
    gap: 10px;
  }

  .site-logo {
    font-size: 1.1rem;
  }
}
