/* ===== 租寓廣告儀表板 — Global Styles ===== */
:root {
  --green: #5FBE91;
  --yellow: #FFE450;
  --blue: #2D8FD2;
  --gray: #3C4650;
  --red: #e74c3c;
  --orange: #f39c12;
  --sidebar-bg: #1e2430;
  --sidebar-hover: #2a3140;
  --sidebar-active: #323b4d;
  --bg: #f3f5f8;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c9b;
  --border: #e4e8ed;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans TC', 'Avenir', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 230px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: #c8d0dc;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .5px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo span { color: var(--green); }

.sidebar-nav { flex: 1; padding: 12px 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: #a0aab8;
  text-decoration: none;
  font-size: 14px;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #dce3ec; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--green); }
.sidebar-nav a .icon { font-size: 17px; width: 22px; text-align: center; }
.sidebar-nav a.disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.nav-section-title {
  padding: 18px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  color: #5a6477;
  letter-spacing: 0.05em;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: #5a6477;
}

.api-status {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--green); }
.dot-yellow { background: var(--orange); }
.dot-red { background: var(--red); }

/* ===== Main Content ===== */
.content {
  margin-left: 230px;
  flex: 1;
  min-height: 100vh;
  padding: 28px 32px;
}

.page { display: none; }
.page.active { display: block; }

/* ===== Auth Banner ===== */
.auth-banner {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 12px 18px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #856404;
}

/* ===== Page Header ===== */
h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
  margin-top: 28px;
}

.date-badge {
  font-size: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--text-light);
  font-weight: 400;
}

/* ===== KPI Cards ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.kpi-card .label { font-size: 12px; color: var(--text-light); margin-bottom: 6px; }
.kpi-card .value { font-size: 28px; font-weight: 700; }
.kpi-card .sub { font-size: 12px; margin-top: 4px; color: var(--text-light); }
.kpi-card .sub.up { color: var(--green); }
.kpi-card .sub.down { color: var(--red); }
.kpi-card .sub.neutral { color: var(--text-light); }

/* ===== Charts ===== */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.chart-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.chart-card.full-width { grid-column: 1 / -1; }
.chart-card h3 { font-size: 14px; color: var(--text-light); margin-bottom: 14px; font-weight: 500; }
.chart-card canvas { max-height: 280px; }

/* ===== Tables ===== */
.table-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #f8f9fb;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr:hover { background: #f8f9fb; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-warning { background: #fff8f0; }
tbody tr.row-warning:hover { background: #fff0e0; }

.status-enabled { color: var(--green); font-weight: 600; }
.status-paused { color: var(--text-light); }
.budget-warn { color: var(--orange); font-weight: 600; }
.budget-danger { color: var(--red); font-weight: 600; }
.qs-low { color: var(--red); font-weight: 600; }
.qs-mid { color: var(--orange); }
.qs-high { color: var(--green); font-weight: 600; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.filter-bar select, .search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
.search-input { width: 240px; }
.search-input::placeholder { color: var(--text-light); }
.search-input:focus, .filter-bar select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(95,190,145,.15);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 4px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #2478b5; }
.btn-secondary { background: #eef0f3; color: var(--text); }
.btn-secondary:hover { background: #dce0e5; }
.btn-danger { background: #fdeaeb; color: var(--red); }
.btn-danger:hover { background: #fad4d6; }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.badge-green { background: #e8f5ef; color: #2d7a50; }
.badge-yellow { background: #fff8e6; color: #8a6d3b; }
.badge-red { background: #fdeaeb; color: #c0392b; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  background: #333;
  opacity: 0;
  transform: translateY(10px);
  transition: all .3s;
  z-index: 9999;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--blue); }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 40px rgba(0,0,0,.15);
}
.modal-content h3 { font-size: 18px; margin-bottom: 8px; }
.modal-content p { color: var(--text-light); font-size: 13px; margin-bottom: 16px; }
.modal-field { margin-bottom: 20px; }
.modal-field label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 6px; }
.modal-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
}
.modal-field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(45,143,210,.15); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Pending Commands ===== */
.pending-commands {
  background: #fff8e6;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}
.pending-commands h3 { font-size: 14px; color: #856404; margin-bottom: 8px; }

/* ===== Loading ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-light);
  font-size: 14px;
  gap: 8px;
}
.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .charts-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-logo, .sidebar-nav a span:last-child, .nav-section-title, .sidebar-footer { display: none; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .content { margin-left: 60px; padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
