/* ===========================================================================
   Gantry UI — dark mode by default, light theme opt-in via [data-theme].
   Pure CSS, no framework: variables + a small set of reusable primitives.
   =========================================================================== */

:root,
:root[data-theme='dark'] {
  --bg: #0f1216;
  --bg-panel: #171c23;
  --bg-raised: #1f2630;
  --bg-hover: #262f3b;
  --border: #2c3543;
  --text: #e6e9ee;
  --text-dim: #8b95a5;
  --accent: #f5a524;
  --accent-contrast: #1a1408;
  --ok: #34c67a;
  --warn: #f5a524;
  --err: #ef5350;
  --info: #4da3ff;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --radius: 8px;
  --mono: 'Cascadia Code', 'JetBrains Mono', Consolas, 'Liberation Mono', monospace;
}

:root[data-theme='light'] {
  --bg: #f4f5f7;
  --bg-panel: #ffffff;
  --bg-raised: #eef0f3;
  --bg-hover: #e5e8ec;
  --border: #d4d9e0;
  --text: #1c222b;
  --text-dim: #5b6572;
  --accent: #c77f00;
  --accent-contrast: #ffffff;
  --shadow: 0 4px 16px rgba(20, 30, 40, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.5 'Segoe UI',
    system-ui,
    -apple-system,
    sans-serif;
}

.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

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

h1,
h2,
h3 {
  font-weight: 600;
  margin: 0 0 0.5rem;
}
h1 {
  font-size: 1.4rem;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 1rem;
}

/* --- Top navigation -------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1.25rem;
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}
.brand .logo {
  color: var(--accent);
  font-size: 1.2rem;
}

.topbar nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.topbar nav a {
  color: var(--text-dim);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  font-weight: 500;
}
.topbar nav a:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.topbar nav a.active {
  color: var(--accent);
  background: var(--bg-raised);
}

.topbar .user-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-dim);
}

/* --- Layout ----------------------------------------------------------------- */
.page {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition:
    border-color 0.15s,
    transform 0.15s;
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.card .card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.stat-row {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
}
.stat {
  flex: 1;
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
}
.stat .stat-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .stat-value {
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Status dots & badges ----------------------------------------------------- */
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.35rem;
}
.dot.ok {
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}
.dot.err {
  background: var(--err);
  box-shadow: 0 0 6px var(--err);
}
.dot.unknown {
  background: var(--text-dim);
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.accent {
  color: var(--accent);
  border-color: var(--accent);
}
.badge.ok {
  color: var(--ok);
  border-color: var(--ok);
}
.badge.err {
  color: var(--err);
  border-color: var(--err);
}

/* --- Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s;
}
.btn:hover {
  background: var(--bg-hover);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn.primary:hover {
  filter: brightness(1.1);
}
.btn.danger {
  color: var(--err);
  border-color: var(--err);
  background: transparent;
}
.btn.danger:hover {
  background: rgba(239, 83, 80, 0.12);
}
.btn.small {
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
}
.btn.ghost {
  background: transparent;
}

/* --- Forms ---------------------------------------------------------------------- */
label.field {
  display: block;
  margin-bottom: 0.75rem;
}
label.field > span {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}
input[type='text'],
input[type='password'],
input[type='number'],
input[type='datetime-local'],
select,
textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}
textarea {
  font-family: var(--mono);
  font-size: 0.85rem;
  min-height: 90px;
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0;
  cursor: pointer;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
.form-error {
  color: var(--err);
  margin: 0.5rem 0;
  min-height: 1.2em;
}

/* --- Tables ---------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tr:hover td {
  background: var(--bg-raised);
}
td.mono,
.mono {
  font-family: var(--mono);
  font-size: 0.82rem;
}
td.actions-cell {
  white-space: nowrap;
  text-align: right;
}

/* --- Tabs ---------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.tabs button:hover {
  color: var(--text);
}
.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Charts ---------------------------------------------------------------------- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1rem;
}
.chart-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.chart-box h3 {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.uplot {
  font: inherit;
}
.uplot .u-legend {
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* --- Logs / terminal output ------------------------------------------------------- */
pre.term {
  background: #0a0d11;
  color: #cdd6e3;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  overflow: auto;
  max-height: 60vh;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
:root[data-theme='light'] pre.term {
  background: #14181d;
}

/* --- Modal ---------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 1rem 1rem;
  z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  padding: 1.25rem;
}
.modal.wide {
  max-width: 860px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* --- Toasts ---------------------------------------------------------------------- */
.toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}
.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  box-shadow: var(--shadow);
  max-width: 380px;
  animation: toast-in 0.2s ease-out;
}
.toast.ok {
  border-left-color: var(--ok);
}
.toast.err {
  border-left-color: var(--err);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- Login ---------------------------------------------------------------------- */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.login-card .brand {
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}
.login-card .tagline {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}

/* --- Misc ---------------------------------------------------------------------- */
.muted {
  color: var(--text-dim);
}
.spacer {
  flex: 1;
}
.mt {
  margin-top: 1rem;
}
.mb {
  margin-bottom: 1rem;
}
.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 2.5rem 1rem;
}
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 1rem;
  font-size: 0.88rem;
}
.kv dt {
  color: var(--text-dim);
}
.kv dd {
  margin: 0;
}
details.audit-details summary {
  cursor: pointer;
  color: var(--info);
  font-size: 0.8rem;
}
details.audit-details pre {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
}
