/* ════════════════════════════════════════════════════════════════════════════
   ASP — "Warm Study" design system
   A cozy, classic, clean light theme: cream paper, warm charcoal ink, a clay
   accent and earthy status colors. Editorial serif for the wordmark + headings,
   a clean humanist sans for the UI, monospace for identifiers.
   Full token reference & usage guidance: DESIGN-SYSTEM.md
   ════════════════════════════════════════════════════════════════════════════ */
:root {
  /* ── Surfaces (warm paper) ───────────────────────────────────────────────── */
  --bg: #f6f1e7;          /* page — warm cream */
  --panel: #fffdf8;       /* cards, bars — near-white warm */
  --panel-2: #efe7d8;     /* raised / hover */
  --border: #e3d8c4;      /* hairline */
  --border-strong: #d6c8ad;

  /* ── Ink ─────────────────────────────────────────────────────────────────── */
  --text: #2c2622;        /* warm near-black */
  --muted: #7a6f63;       /* secondary ink */

  /* ── Brand ───────────────────────────────────────────────────────────────── */
  --accent: #b5512f;      /* clay / terracotta */
  --accent-2: #9d4427;    /* clay, pressed/hover */
  --accent-soft: rgba(181, 81, 47, 0.10);
  --sage: #5e6e54;        /* secondary, calm olive */

  --shadow: 0 6px 26px rgba(74, 52, 30, 0.12);
  --shadow-sm: 0 2px 8px rgba(74, 52, 30, 0.08);

  /* ── Status (earthy, legible) ───────────────────────────────────────────── */
  --ok: #3f7a3f;          /* olive green */
  --warn: #9a6a14;        /* amber */
  --run: #2f6a8a;         /* slate blue */
  --bad: #a8392b;         /* brick */
  --idle: #8a7d6d;        /* stone */
  --pending: #c4b7a3;     /* unrun step */

  /* ── Type ────────────────────────────────────────────────────────────────── */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* ── Geometry ──────────────────────────────────────────────────────────────*/
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over components that set their
   own `display` (e.g. .drawer/.login-view use flex/grid). Without this, those
   panels render on page load regardless of the attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

/* ── Brand ─────────────────────────────────────────────────────────────────── */
.brand {
  font-family: var(--font-serif);
  font-weight: 600; font-size: 19px; letter-spacing: 0.2px;
  display: flex; align-items: center; gap: 9px; color: var(--text);
}
.brand-mark { display: inline-flex; width: 26px; height: 26px; flex: 0 0 auto; }
.brand-mark svg { width: 100%; height: 100%; display: block; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-view {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1100px 560px at 50% -8%, #fbeedd 0%, var(--bg) 58%);
}
.login-card {
  width: 360px; max-width: 100%; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 30px 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  border-top: 3px solid var(--accent);
}
.login-card .brand { font-size: 22px; }
.login-sub { margin: -6px 0 8px; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.login-card input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 12px;
  color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button[type="submit"] {
  margin-top: 6px; background: var(--accent); color: #fff; border: none; border-radius: var(--r-sm);
  padding: 11px; font-weight: 600; letter-spacing: 0.2px;
}
.login-card button[type="submit"]:hover { background: var(--accent-2); }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 0; }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  position: sticky; top: 0; z-index: 5; box-shadow: var(--shadow-sm);
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; }
.ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 7px 12px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 6px 10px; font-size: 14px; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Monitoring ───────────────────────────────────────────────────────────── */
.monitoring-meta { margin: 0 0 14px; }
.monitoring-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.widget {
  margin: 0; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r); padding: 12px; overflow: hidden; box-shadow: var(--shadow-sm);
}
.widget-title { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.widget-img { width: 100%; height: auto; display: block; border-radius: 6px; background: #fff; }
.widget-err { color: var(--muted); font-size: 13px; padding: 28px 12px; text-align: center; }

.content { max-width: 1200px; margin: 0 auto; padding: 24px 22px 40px; }

/* ── Summary cards ─────────────────────────────────────────────────────────── */
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.card .num { font-family: var(--font-serif); font-size: 30px; font-weight: 600; line-height: 1.1; }
.card .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; margin-top: 4px; }
.card.accent { border-color: var(--accent); border-top: 3px solid var(--accent); }
.card.accent .num { color: var(--accent); }

/* ── Toolbar ───────────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { font-family: var(--font-serif); margin: 0; font-size: 21px; font-weight: 600; letter-spacing: 0.2px; }
.toolbar-controls { display: flex; gap: 10px; align-items: center; }
.filter { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
select, .search {
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 8px 10px;
  color: var(--text); font-size: 13px;
}
.search { min-width: 240px; }
select:focus, .search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); overflow: auto; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
  padding: 12px 14px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; background: var(--panel-2);
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.email-cell { display: flex; align-items: center; gap: 6px; }
.email-link { color: var(--accent); text-decoration: none; font-size: 12px; word-break: break-all; }
.email-link:hover { text-decoration: underline; }
.copy-btn { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); border-radius: 6px; padding: 1px 6px; font-size: 12px; line-height: 1.4; }
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.name { font-weight: 600; }
.name-link { color: var(--text); text-decoration: none; }
.name-link:hover { color: var(--accent); text-decoration: underline; }
.sub { color: var(--muted); font-size: 11px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.row-clickable { cursor: pointer; }
.uptime { font-variant-numeric: tabular-nums; color: var(--muted); }
.uptime.live { color: var(--ok); font-weight: 600; }

/* ── Status badge ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
  letter-spacing: 0.3px;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ACTIVE { color: var(--ok); background: rgba(63, 122, 63, 0.12); }
.st-PENDING, .st-PROVISIONING, .st-TERMINATING { color: var(--run); background: rgba(47, 106, 138, 0.12); }
.st-STOPPED { color: var(--warn); background: rgba(154, 106, 20, 0.13); }
.st-FAILED { color: var(--bad); background: rgba(168, 57, 43, 0.12); }
.st-DELETED { color: var(--idle); background: rgba(138, 125, 109, 0.14); }

/* ── Row actions ───────────────────────────────────────────────────────────── */
.actions { display: flex; gap: 6px; white-space: nowrap; }
.btn {
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  border-radius: var(--r-sm); padding: 5px 9px; font-size: 12px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--panel-2); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border: none; border-radius: var(--r-sm); padding: 9px 14px; font-weight: 600; font-size: 13px; letter-spacing: 0.2px; }
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Create modal ──────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(44, 38, 34, 0.45); padding: 20px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 26px;
  width: 400px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
  border-top: 3px solid var(--accent);
}
.modal-card h3 { font-family: var(--font-serif); margin: 0; font-size: 20px; font-weight: 600; }
.modal-sub { margin: -6px 0 4px; color: var(--muted); font-size: 12px; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.modal-card .opt { color: var(--idle); font-weight: 400; }
.modal-card input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 12px;
  color: var(--text); font-size: 14px;
}
.modal-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ── Session detail ────────────────────────────────────────────────────────── */
.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.back-link { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 8px; }
.back-link:hover { color: var(--accent); }
.detail-title { display: flex; align-items: center; gap: 12px; }
.detail-title h2 { font-family: var(--font-serif); margin: 0; font-size: 21px; font-weight: 600; letter-spacing: 0.2px; }

.detail-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 14px; }
.detail-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.detail-cards .detail-card { margin-bottom: 0; }
.detail-card-title { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }

.field-grid { display: flex; flex-direction: column; gap: 12px; }
.field-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 3px; }
.field-value { font-size: 13px; word-break: break-word; }

/* Agent config form */
.cfg-label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.cfg-input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 9px 11px;
  color: var(--text); font-size: 13px; font-family: inherit; resize: vertical;
}
.cfg-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cfg-input:disabled { opacity: 0.6; cursor: not-allowed; }
.cfg-row { display: flex; gap: 14px; flex-wrap: wrap; }
.cfg-row .cfg-label { flex: 1; min-width: 180px; }
.cfg-poll-label { max-width: 160px; }

/* ── Drawer (workflow) ─────────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(44, 38, 34, 0.42); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 100%;
  background: var(--panel); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  z-index: 21; display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { font-family: var(--font-serif); margin: 0; font-size: 18px; font-weight: 600; }
.drawer-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.drawer-body { padding: 18px 20px; overflow: auto; }

/* ── Workflow timeline ─────────────────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 18px 28px; }
.timeline li::before {
  content: ""; position: absolute; left: 7px; top: 18px; bottom: -4px; width: 2px; background: var(--border-strong);
}
.timeline li:last-child::before { display: none; }
.dot {
  position: absolute; left: 0; top: 2px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--panel);
}
.step-name { font-weight: 600; font-size: 13px; }
.step-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.s-succeeded .dot { background: var(--ok); border-color: var(--ok); }
.s-failed .dot { background: var(--bad); border-color: var(--bad); }
.s-running .dot { background: var(--run); border-color: var(--run); animation: pulse 1.2s ease-in-out infinite; }
.s-pending .dot { background: var(--panel); border-color: var(--pending); }
.s-pending .step-name { color: var(--muted); }
.s-compensation .step-name::after { content: " · rollback"; color: var(--warn); font-weight: 400; font-size: 11px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(47, 106, 138, 0.5); } 50% { box-shadow: 0 0 0 5px rgba(47, 106, 138, 0); } }

.exec-status { display: inline-block; margin-bottom: 14px; }
.fail-detail {
  margin-top: 14px; padding: 12px; background: rgba(168, 57, 43, 0.08); border: 1px solid rgba(168, 57, 43, 0.28);
  border-radius: var(--r-sm); font-size: 12px; color: #8a2f24; white-space: pre-wrap; word-break: break-word;
}
.note { color: var(--muted); font-size: 13px; }

details.raw { margin-top: 18px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.raw pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px; overflow: auto; font-size: 11px; max-height: 260px; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--r);
  padding: 11px 16px; box-shadow: var(--shadow); font-size: 13px; max-width: 90%;
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
