/* ============================================================
 * SWTECH Deployment Monitor — Phase 5 UI/UX polish
 * Vanilla CSS only. Light theme + soft gradient.
 * ============================================================ */

* {
  box-sizing: border-box;
}

:root {
  --bg: #f1f5f9;
  --bg-grad-top: #eef2ff;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --shadow: 0 6px 20px rgba(15, 23, 42, .06);
  --input-bg: #f8fafc;
  --thead-bg: #f8fafc;
  --row-border: #f1f5f9;
  --row-hover: #f8fbff;
  --secondary-bg: #e2e8f0;
  --secondary-text: #334155;
  --secondary-hover: #cbd5e1;
  --code-bg: #0f172a;
  --code-text: #fde68a;
  --heading: #334155;
}

/* ---------- Dark theme ---------- */
[data-theme="dark"] {
  --bg: #0b1220;
  --bg-grad-top: #0f172a;
  --panel: #131c2e;
  --border: #243049;
  --text: #e5edf7;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --input-bg: #0e1626;
  --thead-bg: #0e1626;
  --row-border: #1c2638;
  --row-hover: #18233a;
  --secondary-bg: #243049;
  --secondary-text: #cbd5e1;
  --secondary-hover: #2f3d59;
  --code-bg: #020617;
  --code-text: #fde68a;
  --heading: #e2e8f0;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: linear-gradient(180deg, var(--bg-grad-top) 0%, var(--bg) 220px, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans Thai", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, #1e293b 0%, #2563eb 140%);
  color: #fff;
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  font-size: 30px;
  line-height: 1;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .2px;
}

.brand-subtitle {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 2px;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-refreshed {
  font-size: 12px;
  color: #e2e8f0;
}

.btn-refresh {
  background: rgba(255, 255, 255, .15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}

.btn-refresh:hover {
  background: rgba(255, 255, 255, .25);
}

.btn-theme {
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.btn-theme:hover {
  background: rgba(255, 255, 255, .25);
}

/* ---------- Layout ---------- */
.container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px 24px 40px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 20px;
}

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

.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.panel-header .panel-title {
  margin-bottom: 0;
}

/* ---------- Summary cards ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid #94a3b8;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  margin-top: 6px;
}

.accent-success { border-left-color: #16a34a; }
.accent-success .stat-value { color: #16a34a; }
.accent-failed  { border-left-color: #dc2626; }
.accent-failed .stat-value { color: #dc2626; }
.accent-started { border-left-color: #2563eb; }
.accent-started .stat-value { color: #2563eb; }
.accent-other   { border-left-color: #f59e0b; }
.accent-other .stat-value { color: #b45309; }

/* ---------- Filter panel ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-field.filter-grow {
  flex: 1 1 240px;
  min-width: 180px;
}

.filter-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.filter-field input,
.filter-field select {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  min-width: 150px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.filter-field input::placeholder {
  color: var(--muted);
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  transition: background .15s, transform .05s;
}

button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); }

button.secondary {
  background: var(--secondary-bg);
  color: var(--secondary-text);
}

button.secondary:hover { background: var(--secondary-hover); }

.result-info {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Error banner ---------- */
.error-banner {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  font-weight: 600;
}

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--thead-bg);
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .4px;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--row-border);
  vertical-align: top;
}

tbody tr:hover {
  background: var(--row-hover);
}

tbody tr:last-child td {
  border-bottom: none;
}

.nowrap { white-space: nowrap; }

code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 3px 7px;
  border-radius: 7px;
  font-size: 12px;
}

/* ตัดข้อความยาว + tooltip */
.trunc {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.trunc.repo { max-width: 200px; }
.trunc.msg  { max-width: 280px; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.s-success   { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.s-failed    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.s-started   { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.s-cancelled { background: #e2e8f0; color: #475569; border-color: #cbd5e1; }
.s-rollback  { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.s-received  { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.s-unknown   { background: #e2e8f0; color: #475569; border-color: #cbd5e1; }

/* ---------- Environment badges ---------- */
.env-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .3px;
  border: 1px solid transparent;
}

.env-dev   { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.env-sit   { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }
.env-test  { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.env-uat   { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.env-prod  { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; font-weight: 800; }
.env-other { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }

/* ---------- Run button ---------- */
.btn-open {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary-dark);
  border: 1px solid #bfdbfe;
  padding: 5px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.btn-open:hover {
  background: #dbeafe;
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}

.empty-icon { font-size: 42px; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--heading); margin-top: 10px; }
.empty-sub { font-size: 13px; margin-top: 6px; }

/* ---------- Quick filter bar ---------- */
.quick-panel { padding: 12px 16px; }

.quick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.quick-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.quick-btn {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

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

.quick-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.quick-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.auto-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auto-indicator {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.auto-indicator.paused { color: #b45309; }

.btn-auto {
  background: var(--secondary-bg);
  color: var(--secondary-text);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-auto:hover { background: var(--secondary-hover); }

/* ---------- Compact table cells ---------- */
table.compact tbody td { padding: 7px 12px; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
}

.proj-name { font-weight: 600; max-width: 180px; }

.mini-badge {
  display: inline-block;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 6px;
  letter-spacing: .3px;
}

.branch-badge {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 6px;
}

.trunc.dev { max-width: 130px; }
.trunc.server { max-width: 130px; }

/* ---------- Inferred (fallback) markers ---------- */
.infer-mark { color: var(--muted); font-weight: 700; }

.env-badge.inferred { border-style: dashed; opacity: .92; }
.proj-name.inferred { font-style: italic; }

/* ---------- Result info + filter chips ---------- */
.result-info strong { color: var(--text); }

.filter-by {
  color: var(--muted);
  font-weight: 600;
  margin-left: 4px;
}

.chip {
  display: inline-block;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 800px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-inner { padding: 14px 16px; }
  .container { padding: 16px; }
}

@media (max-width: 520px) {
  .summary-grid { grid-template-columns: 1fr; }
  .filter-field, .filter-field input, .filter-field select { width: 100%; }
  .filter-field { flex: 1 1 100%; }
}

/* ---------- Dark-mode element tweaks ---------- */
[data-theme="dark"] .error-banner {
  background: #2a1416;
  color: #fca5a5;
  border-color: #5b2326;
}

[data-theme="dark"] .btn-open {
  background: #15294a;
  color: #93c5fd;
  border-color: #2b4a7e;
}

[data-theme="dark"] .btn-open:hover {
  background: #1d365c;
}
