/* ==========================================================================
   KIRIMURE / MAER DESIGN SYSTEM — CORE COMPONENTS
   Requires tokens.css to be loaded first.
   Zero hardcoded colors: every rule resolves through CSS custom properties.
   ========================================================================== */

/* ---------- reset & base ---------- */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  transition: background var(--duration-slow) var(--ease), color var(--duration-slow) var(--ease);
}
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.01em; margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
}
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- layout ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: var(--space-8) var(--space-8) 80px; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}
.page-head h1 { font-size: var(--text-2xl); font-weight: 600; }
.page-head p { color: var(--text-dim); font-size: var(--text-base); margin: 2px 0 0; }

/* ---------- header / top nav ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 14px var(--space-8);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-left, .header-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .brand-mark { color: var(--accent); flex-shrink: 0; }
.brand .brand-tld { color: var(--accent); }

.segmented-nav { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-lg); }
.segmented-nav button, .segmented-nav a {
  background: transparent; border: none; padding: 7px 16px; border-radius: 7px;
  font-size: var(--text-base); font-weight: 500; color: var(--text-dim); text-decoration: none;
}
.segmented-nav .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  white-space: nowrap;
}
.icon-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.icon-toggle:hover { color: var(--text); background: var(--surface-2); }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 9px 16px;
  font-size: var(--text-base);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-text { color: var(--danger); border-color: var(--danger-bg); background: transparent; }
.btn-danger-text:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn-danger { background: var(--danger); color: #FFFFFF; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 11px; font-size: var(--text-sm); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); }
.section-card { padding: 22px 24px; margin-bottom: var(--space-5); }
.section-card h2, .section-card h3 { font-size: var(--text-md); font-weight: 600; margin-bottom: var(--space-4); }

/* ---------- shared-border stat tiles ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin-bottom: var(--space-6);
}
.stat { background: var(--surface); padding: var(--space-4) var(--space-5); }
.stat .eyebrow { margin-bottom: 6px; }
.stat .value { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600; line-height: 1.2; }
.stat .stat-meta { font-size: var(--text-xs); color: var(--text-faint); margin-top: 4px; font-family: var(--font-mono); }
.stat.warn-stat .value { color: var(--danger); }
.stat.caution-stat .value { color: var(--warn); }
.stat.ok-stat .value { color: var(--success); }

/* ---------- filter bar & chips ---------- */
.filter-bar { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.search-input {
  flex: 1;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: var(--text-base);
  color: var(--text);
  font-family: inherit;
}
.search-input::placeholder { color: var(--text-faint); }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  padding: 7px 13px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.chip:hover:not(.active) { background: var(--surface-2); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- hairline table ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-xl); overflow-x: auto; background: var(--surface); }
.table-wrap table, table.table { width: 100%; border-collapse: collapse; }
.table-wrap thead th, table.table thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-wrap tbody tr, table.table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--duration-fast) var(--ease);
}
.table-wrap tbody tr:last-child, table.table tbody tr:last-child { border-bottom: none; }
.table-wrap tbody tr:hover, table.table tbody tr:hover { background: var(--surface-2); }
.table-wrap tbody tr.row-alert, table.table tbody tr.row-alert { box-shadow: inset 3px 0 0 var(--danger); }
.table-wrap tbody tr.row-warn, table.table tbody tr.row-warn { box-shadow: inset 3px 0 0 var(--warn); }
.table-wrap td, table.table td { padding: 13px 18px; font-size: var(--text-base); vertical-align: middle; }

/* ---------- status badges ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-success { background: var(--success-bg); color: var(--success); }
.status-danger  { background: var(--danger-bg);  color: var(--danger); }
.status-warn    { background: var(--warn-bg);    color: var(--warn); }
.status-accent  { background: var(--accent-soft); color: var(--accent); }
.status-neutral { background: var(--surface-2);  color: var(--text-dim); }

/* ---------- icon buttons & empty state ---------- */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.icon-btn {
  width: 28px; height: 28px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text-faint);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }
.empty-state { padding: 48px 24px; text-align: center; color: var(--text-dim); }
.empty-state h3 { color: var(--text); margin-bottom: 6px; font-size: var(--text-md); }
.empty-state p { margin: 0; font-size: var(--text-base); }

/* ---------- settings / side-tab layout ---------- */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: var(--space-8); align-items: start; }
.side-tabs { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 82px; }
.side-tabs button, .side-tabs a {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  color: var(--text-dim);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.side-tabs button.active, .side-tabs a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.side-tabs button:hover:not(.active), .side-tabs a:hover:not(.active) { color: var(--text); text-decoration: none; }

/* ---------- field rows & usage bar ---------- */
.field-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.field-row:last-child { border-bottom: none; }
.field-label { font-size: var(--text-xs); color: var(--text-faint); font-family: var(--font-mono); letter-spacing: 0.05em; text-transform: uppercase; }
.field-value { font-size: var(--text-base); font-weight: 500; }
.usage-bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.usage-fill { height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- form controls ---------- */
.form-group { margin-bottom: var(--space-4); }
.form-group label { display: block; font-size: var(--text-sm); color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }
.form-hint { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.form-control,
input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: var(--text-base);
  color: var(--text);
  font-family: inherit;
}
.search-input { background: var(--surface); } /* keeps search distinct on canvas */
textarea.mono { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6; }
select { cursor: pointer; }
fieldset[disabled] { opacity: 0.78; }

/* ---------- banners & toasts ---------- */
.warn-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  border-radius: var(--radius-xl);
  padding: 14px 20px;
  margin-bottom: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  color: var(--warn);
  font-size: var(--text-sm);
  font-weight: 500;
}
.close-btn {
  width: 30px; height: 30px; border-radius: var(--radius-md); border: none;
  background: var(--surface-2); color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center;
}
.close-btn:hover { color: var(--text); }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all var(--duration-slow) var(--ease);
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .app-header { padding: 12px 16px; flex-wrap: wrap; }
  .container { padding: 20px 16px 60px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .settings-layout { grid-template-columns: 1fr; gap: var(--space-5); }
  .side-tabs { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .side-tabs button, .side-tabs a { width: auto; white-space: nowrap; }
}
