/* 803 轉診系統 - 樣式表 */

:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #dde2e7;
  --color-text: #1f2933;
  --color-text-muted: #5c6b7a;
  --color-primary: #1c5faa;
  --color-primary-dark: #124173;
  --color-danger: #c0392b;
  --color-warn-bg: #fff6e5;
  --color-warn-border: #f0c36d;
  --color-error-bg: #fdecea;
  --color-error-border: #e5978c;
  --color-success-bg: #eaf7ee;
  --color-success-border: #8fcf9f;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC",
    "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0.2em 0 0.6em; }
h2 { font-size: 1.15rem; margin: 0 0 0.5em; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/* ------------------ Topbar ------------------ */
.topbar {
  background: var(--color-primary-dark);
  color: #fff;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; opacity: 0.9; }
.mainnav { display: flex; gap: 1rem; flex-wrap: wrap; flex: 1; }
.mainnav a { color: #dbe9f7; font-size: 0.95rem; }
.mainnav a:hover { color: #fff; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: #dbe9f7;
}

/* ------------------ Forms ------------------ */
.form { display: flex; flex-direction: column; gap: 1rem; max-width: 640px; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group-checkbox { flex-direction: row; align-items: center; }
label { font-weight: 600; font-size: 0.92rem; }
input[type=text], input[type=password], input[type=email], input[type=file],
select, textarea {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--color-text);
  width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(28, 95, 170, 0.15);
}
.field-hint { font-size: 0.83rem; color: var(--color-text-muted); margin: 0; }
.field-hint-ok { color: #2b8a3e; }
.field-hint-error { color: var(--color-danger); }

.inline-form { display: inline; }

/* ------------------ Buttons ------------------ */
.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: #eef1f4;
  color: var(--color-text);
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; border-color: var(--color-border); }
.btn-small { padding: 0.32rem 0.7rem; font-size: 0.85rem; }
.btn-block { width: 100%; text-align: center; }
.btn-link { background: transparent; border: none; color: #dbe9f7; padding: 0; text-decoration: underline; }
.btn-danger-outline { background: #fff; border-color: var(--color-danger); color: var(--color-danger); }
.btn-danger-outline:hover { background: var(--color-error-bg); }

/* ------------------ Panels ------------------ */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.panel-narrow { max-width: 480px; }
.panel-wide { max-width: 900px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

/* ------------------ Auth ------------------ */
.auth-box {
  max-width: 380px;
  margin: 3rem auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
}
.auth-box h1 { text-align: center; font-size: 1.3rem; }
.subtitle { text-align: center; color: var(--color-text-muted); margin-top: -0.4em; margin-bottom: 1.5rem; font-size: 0.9rem; }

/* ------------------ Alerts ------------------ */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-warn { background: var(--color-warn-bg); border-color: var(--color-warn-border); }
.alert-error { background: var(--color-error-bg); border-color: var(--color-error-border); }
.alert-success { background: var(--color-success-bg); border-color: var(--color-success-border); }
.alert-list { margin: 0.4em 0 0; padding-left: 1.2em; }

/* ------------------ Badges ------------------ */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
}
.badge-lg { font-size: 0.9rem; padding: 0.25rem 0.8rem; }
.badge-blue { background: #1c5faa; }
.badge-teal { background: #0f9b8e; }
.badge-purple { background: #7048b3; }
.badge-green { background: #2b8a3e; }
.badge-red { background: #c0392b; }
.badge-gray { background: #7a8794; }

/* ------------------ Tables ------------------ */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}
.data-table th { color: var(--color-text-muted); font-weight: 600; font-size: 0.85rem; }
.data-table td:nth-child(4), .kv-table td { white-space: normal; }

.kv-table { width: 100%; border-collapse: collapse; }
.kv-table th {
  text-align: left;
  width: 30%;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem 0.4rem 0;
  vertical-align: top;
}
.kv-table td { padding: 0.4rem 0; vertical-align: top; }

.mono-small { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; color: var(--color-text-muted); }

/* ------------------ Dashboard stats ------------------ */
.stat-row { display: flex; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.3rem;
}
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--color-primary); }
.stat-label { color: var(--color-text-muted); font-size: 0.85rem; }

/* ------------------ Detail page ------------------ */
.meta-line { color: var(--color-text-muted); font-size: 0.9rem; }
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin: 1.25rem 0;
}
.detail-block-wide { grid-column: 1 / -1; }
.detail-block h2 { font-size: 1rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3rem; }

.attachment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }

.fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; margin: 0; display: flex; flex-direction: column; gap: 0.9rem; }
.fieldset legend { padding: 0 0.4rem; font-weight: 700; color: var(--color-primary-dark); }

.action-bar { display: flex; flex-direction: column; gap: 1rem; border-top: 1px solid var(--color-border); padding-top: 1rem; }
.action-details summary { cursor: pointer; font-weight: 600; margin-bottom: 0.6rem; }

/* ------------------ Timeline ------------------ */
.timeline { display: flex; align-items: flex-start; margin: 1rem 0 1.5rem; }
.timeline-step {
  flex: 1;
  text-align: center;
  position: relative;
  color: var(--color-text-muted);
}
.timeline-step::before {
  content: '';
  position: absolute;
  top: 8px;
  left: -50%;
  width: 100%;
  height: 2px;
  background: var(--color-border);
  z-index: 0;
}
.timeline-step:first-child::before { display: none; }
.timeline-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-border);
  margin: 0 auto 0.4rem;
  position: relative;
  z-index: 1;
}
.timeline-done { color: var(--color-primary-dark); font-weight: 600; }
.timeline-done .timeline-dot { background: var(--color-primary); }
.timeline-label { font-size: 0.8rem; }

.pagination { display: flex; gap: 0.6rem; margin-top: 1rem; }

.empty-text { color: var(--color-text-muted); font-style: italic; }

.sitefooter {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  padding: 2rem 1rem 1rem;
}

/* ------------------ RWD ------------------ */
@media (max-width: 720px) {
  .detail-grid { grid-template-columns: 1fr; }
  .topbar-inner { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .mainnav { gap: 0.7rem; }
  .stat-row { flex-direction: column; }
}
