:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* 動態防截圖浮水印 */
.watermark-layer {
  position: fixed;
  inset: 0;
  z-index: 900;
  pointer-events: none;
  background-repeat: repeat;
  opacity: 0.45;
}

/* 登入畫面 */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.25);
}

.login-brand { text-align: center; margin-bottom: 24px; }
.brand-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}
.login-brand h1 { margin: 4px 0; font-size: 22px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.login-footnote { margin: 20px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* Topbar & Tabs */
.topbar {
  background: #0f172a;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-logo { font-weight: 700; font-size: 16px; }
.scope-badge {
  background: rgba(59, 130, 246, 0.28);
  border: 1px solid rgba(147, 197, 253, 0.4);
  color: #dbeafe;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.user-name { font-size: 14px; color: #e2e8f0; }

.nav-tabs {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.main-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards & Forms */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.card h2 { margin: 0; font-size: 18px; }
.card h3 { margin: 0; font-size: 16px; }
.muted-text { color: var(--muted); font-size: 13px; }

.stack-form { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 600; color: #334155; }
.form-group input, .form-group select {
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 14px;
  background: #fff;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
}
.filter-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.inline-search {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.inline-search input { flex: 1; min-width: 240px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 7px; font-size: 14px; }
.inline-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; color: #334155; border-color: #cbd5e1; }
.btn-outline:hover { background: #f8fafc; }
.btn-ghost { background: rgba(255, 255, 255, 0.12); color: #fff; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.22); }
.btn-danger-outline { background: #fff; color: var(--danger); border-color: #fecaca; }

/* Tables */
.table-wrap { overflow-x: auto; max-height: 62vh; border: 1px solid var(--border); border-radius: 8px; }
.compact-table { max-height: 360px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.data-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  font-weight: 700;
  color: #334155;
  z-index: 2;
}
.data-table tbody tr:hover { background: #f1f5f9; }
.empty-cell { text-align: center !important; color: var(--muted); padding: 28px !important; }
.link-name { color: var(--primary); font-weight: 600; cursor: pointer; text-decoration: underline; }

/* Badges & Pills */
.count-pill {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  margin-left: 6px;
}
.count-pill.warn { background: #fef3c7; color: #92400e; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.tag-ok { background: #dcfce7; color: #166534; }
.tag-no { background: #fee2e2; color: #991b1b; }
.tag-info { background: #dbeafe; color: #1e40af; }

/* Journey Cards */
.journey-list { display: flex; flex-direction: column; gap: 16px; }
.journey-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.journey-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.journey-stages {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.stage-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}
.stage-box.done { border-color: #86efac; background: #f0fdf4; }
.stage-title { font-weight: 700; margin-bottom: 6px; display: flex; justify-content: space-between; }
.stage-item { font-size: 13px; padding: 6px 0; border-top: 1px dashed #cbd5e1; }

/* Dashboard KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.kpi-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 14px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; color: #0f172a; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.two-col-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 18px; }

/* Drop Zone */
.drop-zone {
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  padding: 32px 20px;
  text-align: center;
  background: #f8fafc;
  margin-top: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.dragover { border-color: var(--primary); background: #eff6ff; }
.drop-title { font-weight: 700; margin: 0 0 6px; }
.import-preview { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.progress-text { font-size: 13px; color: var(--primary); font-weight: 600; }

/* Alerts & Modals & Toast */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #eff6ff; color: #1e40af; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.checkbox-row { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; }
.checkbox-row label { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; cursor: pointer; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 1100;
}

.nav-tabs, .table-wrap {
  -webkit-overflow-scrolling: touch;
}

/* 平板與手機觸控優化 */
@media (max-width: 900px) {
  .form-group input,
  .form-group select,
  .inline-search input,
  .inline-controls select {
    font-size: 16px; /* 防止 iOS 點擊輸入時自動放大畫面 */
    min-height: 44px;
  }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .tab-btn { padding: 14px 14px; font-size: 15px; }
  .fc-visible { width: 20px; height: 20px; cursor: pointer; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 手機直向專屬排版 */
@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .nav-tabs { padding: 0 10px; gap: 2px; }
  .main-content { padding: 12px 10px; }
  .card { padding: 14px; margin-bottom: 14px; }
  .login-card { padding: 24px 18px; }

  .filter-grid { grid-template-columns: 1fr; gap: 10px; }
  .filter-actions { flex-direction: column; }
  .filter-actions .btn { width: 100%; }

  .inline-search { flex-direction: column; }
  .inline-search input, .inline-search .btn { width: 100%; min-width: 0; }

  .inline-controls { width: 100%; }
  .inline-controls select, .inline-controls .btn { flex: 1 1 auto; }

  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-value { font-size: 22px; }

  .two-col-grid { grid-template-columns: 1fr; }
  .table-wrap { max-height: 55vh; }
  .data-table th, .data-table td { padding: 10px 10px; font-size: 13px; }

  .modal-card { padding: 18px 16px; }
  .toast {
    left: 14px;
    right: 14px;
    bottom: 16px;
    text-align: center;
  }
}
