@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg:           #07090e;
  --surface:      #0d1117;
  --surface-2:    #141b26;
  --surface-3:    #1b2333;
  --border:       #1e2a3a;
  --border-2:     #253040;
  --text:         #dce4ef;
  --text-2:       #a8b6cc;
  --muted:        #5c6f87;
  --gold:         #c8a84b;
  --gold-bright:  #e2c46a;
  --gold-dim:     #8a7030;
  --gold-glow:    rgba(200, 168, 75, 0.12);
  --gold-border:  rgba(200, 168, 75, 0.28);
  --danger:       #e05252;
  --danger-glow:  rgba(224, 82, 82, 0.12);
  --ok:           #3ecb80;
  --ok-glow:      rgba(62, 203, 128, 0.12);
  --nav-width:    220px;
  --header-h:     58px;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.45);
  --shadow-md:    0 4px 16px rgba(0,0,0,.55);
  --shadow-lg:    0 12px 40px rgba(0,0,0,.65);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ──────────────────────────────────────────────── */

.login-page {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 70% 60% at 50% -10%, rgba(200,168,75,.08) 0%, transparent 70%),
    var(--bg);
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-brand-name {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-transform: uppercase;
}

.login-brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 0.2rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

/* ─── Top header ─────────────────────────────────────────── */

.top {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(200,168,75,.06);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
}

.brand strong {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
  background: linear-gradient(90deg, var(--gold-bright), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand .muted {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* ─── Layout ─────────────────────────────────────────────── */

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ─── Sidebar nav ────────────────────────────────────────── */

.nav {
  width: var(--nav-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex-shrink: 0;
  overflow-y: auto;
}

.nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.4rem 0.65rem 0.2rem;
  margin-top: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 450;
  font-family: inherit;
  position: relative;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.01em;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-item.active {
  background: var(--gold-glow);
  color: var(--gold-bright);
  font-weight: 550;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--gold);
}

/* ─── Main content ───────────────────────────────────────── */

.main {
  flex: 1;
  padding: 1.75rem 2rem 3rem;
  overflow: auto;
  background: var(--bg);
}

.view.hidden { display: none; }

/* ─── Toolbar ────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.toolbar h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ─── Card ───────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* ─── Filters ────────────────────────────────────────────── */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.filters input,
.filters select {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.855rem;
  font-family: inherit;
  min-width: 10rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filters input:focus,
.filters select:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

/* ─── Table ──────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.855rem;
}

thead tr {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-2);
}

th {
  text-align: left;
  padding: 0.65rem 0.75rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

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

tbody tr:hover td {
  background: var(--surface-2);
}

.table-head { background: var(--surface-2); }

/* ─── Mono ───────────────────────────────────────────────── */

.mono {
  font-family: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.78rem;
  word-break: break-all;
  color: var(--text-2);
}

/* ─── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.48rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.855rem;
  font-weight: 450;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-2);
  color: var(--text);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--gold-glow);
  border-color: var(--gold-dim);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.primary {
  background: linear-gradient(135deg, var(--gold-bright) 0%, var(--gold) 100%);
  border-color: transparent;
  color: #080a0e;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(200,168,75,.25);
}

.btn.primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 14px rgba(200,168,75,.35);
}

.btn.full { width: 100%; justify-content: center; }

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.danger {
  border-color: rgba(224,82,82,.35);
  color: var(--danger);
  background: var(--surface-2);
}

.btn.danger:hover {
  background: var(--danger-glow);
  border-color: var(--danger);
}

.btn.small {
  padding: 0.28rem 0.6rem;
  font-size: 0.78rem;
}

/* ─── Badge ──────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.badge.ok {
  background: var(--ok-glow);
  border-color: rgba(62,203,128,.3);
  color: var(--ok);
}

.badge.err {
  background: var(--danger-glow);
  border-color: rgba(224,82,82,.3);
  color: var(--danger);
}

/* ─── Form fields ────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.field span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.01em;
}

.field input,
.field select,
.field textarea {
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

.field textarea {
  min-height: 5.5rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.8rem;
  resize: vertical;
}

/* ─── Rule form ──────────────────────────────────────────── */

.targets-grid {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.target-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 0.55rem 0.7rem;
}

.rule-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
}

.rule-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  background: var(--bg);
}

.rule-section-title {
  margin: 0 0 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
}

.rule-form-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
}

.rule-enabled-row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.rule-enabled-row span { margin: 0; }

/* ─── Simulate ───────────────────────────────────────────── */

.sim-result { margin-top: 0.4rem; }

.sim-list {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.sim-match-item {
  margin: 0.4rem 0 0;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.845rem;
}

.sim-match-current {
  border-color: var(--gold-border);
  background: var(--gold-glow);
  box-shadow: inset 3px 0 0 var(--gold);
}

.sim-editing-badge {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.68rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--gold-glow);
  color: var(--gold-bright);
  border: 1px solid var(--gold-border);
  font-weight: 600;
  vertical-align: middle;
}

/* ─── Targets / Scope ────────────────────────────────────── */

.target-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.target-extra {
  margin-top: 0.45rem;
  width: 100%;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.855rem;
  outline: none;
}

.scope-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
}

.scope-grid-compact .scope-check { font-size: 0.82rem; }

.scope-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 0.855rem;
}

/* ─── Stack badges ───────────────────────────────────────── */

.stack-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.stack-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.14rem 0.45rem;
  border-radius: 999px;
  background: var(--gold-glow);
  color: var(--gold-bright);
  border: 1px solid var(--gold-border);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* ─── Row actions ────────────────────────────────────────── */

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.rule-row-clickable { cursor: pointer; }

.rule-row-clickable:hover td {
  background: var(--surface-2);
}

.rule-row-clickable:focus {
  outline: none;
}

.rule-row-clickable:focus td:first-child {
  box-shadow: inset 3px 0 0 var(--gold);
}

.rule-row-actions { cursor: default; }

/* ─── Separator ──────────────────────────────────────────── */

.sep {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* ─── Error / Misc ───────────────────────────────────────── */

.error {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.84rem;
}

.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

code {
  font-size: 0.84em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--gold-bright);
}

/* ─── Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  max-width: 22rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast.hidden { display: none; }

.toast.err {
  border-color: rgba(224,82,82,.45);
  background: #120d0d;
}

/* ─── Modal ──────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: min(34rem, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-top: 2px solid var(--gold);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-panel.modal-wide {
  width: min(76rem, 98vw);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 0.975rem;
  font-weight: 600;
  color: var(--text);
}

.modal-body {
  padding: 1.25rem;
}

/* ─── Footer ─────────────────────────────────────────────── */

.foot {
  padding: 0.65rem 1.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  letter-spacing: 0.02em;
}

/* ─── Scrollbar ──────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ─── Inputs global focus ring ───────────────────────────── */

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--gold-dim) !important;
  box-shadow: 0 0 0 3px var(--gold-glow) !important;
}

input[type="checkbox"] {
  accent-color: var(--gold);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ─── Responsive ─────────────────────────────────────────── */

/* Tablet */
@media (max-width: 980px) {
  .rule-form-grid   { grid-template-columns: 1fr; }
  .targets-grid     { grid-template-columns: 1fr; }
  .rule-form-inline { grid-template-columns: 1fr; }
  .scope-grid       { grid-template-columns: 1fr; }
  :root             { --nav-width: 190px; }
  .main             { padding: 1.25rem 1rem 2rem; }
  .toolbar h1       { font-size: 1.15rem; }
}

/* Mobile */
@media (max-width: 680px) {
  /* Nav becomes overlay drawer */
  .nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-lg);
    border-right: 1px solid var(--border-2);
  }

  .nav.open {
    transform: translateX(0);
  }

  .nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-h);
    background: rgba(0,0,0,.55);
    z-index: 89;
    backdrop-filter: blur(1px);
  }

  .nav-overlay.open { display: block; }

  /* Show hamburger, hide less-critical top items */
  .nav-toggle     { display: inline-flex !important; }
  .top-btn-hide   { display: none !important; }
  .top-user       { display: none !important; }

  /* Main takes full width */
  .layout { flex-direction: column; }
  .main   { padding: 1rem 0.85rem 2.5rem; }

  /* Card & toolbar adjustments */
  .card       { padding: 0.85rem; }
  .toolbar    { flex-wrap: wrap; gap: 0.5rem; }
  .toolbar h1 { font-size: 1.05rem; }

  /* Filters stack vertically */
  .filters { flex-direction: column; align-items: stretch; }
  .filters input,
  .filters select { min-width: 0; width: 100%; }

  /* Table horizontal scroll with sticky first col */
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Modal full-width */
  .modal-panel {
    width: 100% !important;
    max-height: 95vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    border-top: 2px solid var(--gold);
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  /* Toast full width */
  .toast {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 1rem;
    max-width: none;
  }
}

/* Hide hamburger on desktop */
.nav-toggle { display: none; }
