/* ---------------------------------------------------------------------------
   Discord AI Rules portal — visual design
   Discord-blurple accent, soft dark surface, card-based layout.
--------------------------------------------------------------------------- */
:root {
  --blurple: #5865f2;
  --blurple-600: #4752c4;
  --bg: #0f1117;
  --bg-2: #161924;
  --surface: #1c2030;
  --surface-2: #232838;
  --line: #2c3245;
  --text: #e7e9f0;
  --muted: #9aa1b5;
  --green: #3ba55d;
  --red: #ed4245;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(88, 101, 242, 0.18), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(59, 165, 93, 0.08), transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }

/* ---- Brand ---- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--blurple), #8a5cf6);
  color: #fff; font-size: 18px; box-shadow: 0 6px 16px rgba(88, 101, 242, 0.45);
}
.brand h1 { font-size: 20px; }
.brand h1 span { color: var(--blurple); }

/* ---- Buttons ---- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; color: var(--text);
  background: var(--surface-2); transition: transform .06s ease, background .15s ease, opacity .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--blurple); border-color: var(--blurple); color: #fff; }
.btn-primary:hover { background: var(--blurple-600); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 10px; }
.btn-danger-ghost:hover { color: var(--red); background: rgba(237, 66, 69, 0.1); }

/* ---- Cards ---- */
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* =================== LOGIN =================== */
.login-body { display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 420px; text-align: center; }
.login-card .brand { justify-content: center; margin-bottom: 14px; }
.tagline { color: var(--muted); line-height: 1.5; margin-bottom: 22px; }
.login-form { display: grid; gap: 8px; text-align: left; }
.login-form label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-form input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.login-form input:focus { border-color: var(--blurple); box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.25); }
.login-form .btn { margin-top: 14px; }
.muted { color: var(--muted); font-weight: 400; }
.dev-note { margin-top: 18px; font-size: 12px; color: var(--muted); }
.form-error { color: #ff8a8c; font-size: 13px; margin-top: 6px; }
.dev-banner {
  background: #5a2a00; color: #ffd9a8; text-align: center;
  padding: 8px 14px; font-size: 13px; font-weight: 600;
  border-bottom: 1px solid #7a3c00; letter-spacing: 0.2px;
}

/* =================== DASHBOARD =================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 23, 0.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.guild-chip {
  font-size: 13px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px;
}
.wrap { max-width: 820px; margin: 0 auto; padding: 28px 22px 80px; display: grid; gap: 26px; }

.section-sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.composer h2 { font-size: 18px; }
.composer textarea {
  width: 100%; margin-top: 14px; resize: vertical;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.composer textarea:focus { border-color: var(--blurple); box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.22); }

.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.examples-label { font-size: 13px; color: var(--muted); margin-right: 2px; }
.chip {
  font: inherit; font-size: 12.5px; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
  transition: color .15s ease, border-color .15s ease;
}
.chip-example:hover { color: var(--text); border-color: var(--blurple); }

.composer-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.composer-status { font-size: 13px; color: var(--muted); }
.composer-status.spinner::before {
  content: ""; display: inline-block; width: 13px; height: 13px;
  margin-right: 7px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--blurple);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Rules list ---- */
.rules-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.rules-head h2 { font-size: 18px; display: flex; align-items: center; gap: 10px; }
.rule-search {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  width: 240px; max-width: 46vw; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.rule-search::placeholder { color: var(--muted); }
.rule-search:focus { border-color: var(--blurple); box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.22); }
/* Search filter hide: a utility with !important so it wins over any card display
   rule. Non-destructive — the card stays in the DOM and reappears when cleared. */
.hidden-by-search { display: none !important; }
.count-badge {
  font-size: 13px; font-weight: 700; color: var(--blurple);
  background: rgba(88, 101, 242, 0.15); border-radius: 999px; padding: 2px 10px;
}
.rule-list { display: grid; gap: 14px; }

.empty { text-align: center; color: var(--muted); padding: 44px 20px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-mark { font-size: 26px; opacity: .5; margin-bottom: 8px; }

/* ---- A single rule card ---- */
.rule-card { padding: 18px 20px; }
.rule-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.rule-name { font-size: 16px; }
.rule-card.disabled { opacity: 0.6; }
.rule-card.disabled .rule-name { text-decoration: line-through; text-decoration-color: var(--muted); }

.cap-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.cap-chip {
  font-size: 12.5px; color: #cdd2e6;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px;
}

/* ---- Create receipt: advisory reference warnings (heads-up, not an error) ---- */
.ref-receipt { display: grid; gap: 8px; margin: 12px 0 4px; }
.ref-warn {
  border: 1px solid #7a5a1e; border-left-width: 3px;
  background: rgba(255, 196, 84, 0.06); border-radius: 8px;
  padding: 9px 12px;
}
.ref-warn-msg { font-size: 13px; color: #ffd9a8; line-height: 1.45; }
.ref-warn-suggest {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px;
}
.ref-warn-label { font-size: 12.5px; color: var(--muted); }
.ref-apply {
  padding: 4px 10px; font-size: 12.5px;
  border-color: var(--blurple); color: #cdd2e6;
}
.ref-apply:hover { color: #fff; background: rgba(88, 101, 242, 0.18); }
.ref-apply:disabled { opacity: .55; cursor: default; }
.ref-warn-error { margin-top: 6px; }

/* ---- Authoring questions: advisory "you left this vague" nudge (a prompt, not an error) ---- */
.authoring-questions { display: grid; gap: 8px; margin: 12px 0 4px; }
.aq-item {
  border: 1px solid var(--blurple); border-left-width: 3px;
  background: rgba(88, 101, 242, 0.06); border-radius: 8px;
  padding: 9px 12px;
}
.aq-msg { font-size: 13px; color: #cdd2e6; line-height: 1.45; }
.aq-options {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px;
}
.aq-choice {
  padding: 4px 10px; font-size: 12.5px;
  border-color: var(--blurple); color: #cdd2e6;
}
.aq-choice:hover { color: #fff; background: rgba(88, 101, 242, 0.18); }
.aq-choice:disabled { opacity: .55; cursor: default; }
.aq-error { margin-top: 6px; }

/* ---- Derived category silos: group headers + the spanning badge ---- */
.rule-group { margin-top: 22px; }
.rule-group:first-child { margin-top: 0; }
.rule-group-head {
  margin: 0 0 10px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
/* Badge on a card whose capabilities span >1 category (shown in its dominant
   silo, labeled with every silo it belongs to — so it never silently vanishes). */
.cat-span {
  display: inline-block; margin-bottom: 10px;
  font-size: 11.5px; color: var(--muted);
  border: 1px dashed rgba(148, 155, 178, 0.45); border-radius: 6px;
  padding: 2px 8px;
}

.rule-source { margin-top: 10px; }
.rule-source summary { cursor: pointer; font-size: 12.5px; color: var(--muted); list-style: none; }
.rule-source summary::-webkit-details-marker { display: none; }
.rule-source summary::before { content: "▸ "; }
.rule-source[open] summary::before { content: "▾ "; }
.source-text { margin-top: 8px; font-size: 13px; color: #cdd2e6; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }

.rule-card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.rule-meta { font-size: 12px; color: var(--muted); }
.rule-actions { display: flex; align-items: center; gap: 8px; }
.btn-edit { padding: 6px 12px; }

/* ---- Tier-1 quick-edit fields (inside the unified edit panel) ---- */
.tier1-section { margin-bottom: 4px; }
.tier1-fields { display: grid; gap: 12px; margin-top: 8px; }
.t1-note { font-size: 13px; color: var(--muted); margin: 4px 0; }
.t1-note-warn { color: #ffd9a8; }

.t1-cap-block {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); padding: 12px 14px;
}
.t1-cap-title {
  font-size: 11.5px; font-weight: 700; color: var(--blurple);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px;
}
.t1-row {
  display: flex; align-items: center; gap: 12px;
  padding: 5px 0; flex-wrap: wrap;
}
.t1-label {
  flex: 0 0 140px; font-size: 12.5px; color: var(--muted);
}
.t1-control {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.t1-control:focus { border-color: var(--blurple); box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.2); }
.t1-select, .t1-text { flex: 1 1 200px; min-width: 0; }
.t1-number { width: 110px; }
.t1-number-sm { width: 84px; }
.t1-readonly {
  flex: 1 1 200px; min-width: 0; font-size: 13px; color: #cdd2e6;
  background: var(--surface); border: 1px dashed var(--line);
  border-radius: 8px; padding: 8px 10px;
}
.t1-scoring { flex: 1 1 200px; display: grid; gap: 6px; }
.t1-scoring-line { display: flex; align-items: center; gap: 10px; }
.t1-scoring-desc { font-size: 12.5px; color: #cdd2e6; }

.tier1-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.t1-status { font-size: 13px; color: var(--muted); }

/* Tier-1 plain-value confirm beat — same register as the Tier-2 review box. */
.t1-confirm {
  margin-top: 14px; padding: 16px;
  border: 1px solid var(--blurple); border-radius: 12px;
  background: rgba(88, 101, 242, 0.06);
}
.t1-confirm-list { list-style: none; margin: 8px 0 14px; padding: 0; display: grid; gap: 8px; }
.t1-confirm-list li { font-size: 13px; color: #cdd2e6; line-height: 1.5; }
.t1-diff-field { color: var(--blurple); font-weight: 600; }
.t1-diff-old { color: var(--muted); }
.t1-diff-new { color: var(--text); font-weight: 600; }

/* Stale-spec (409) affordance. */
.t1-stale {
  margin-top: 14px; padding: 14px 16px;
  border: 1px solid #7a3c00; border-radius: 12px; background: #2a1500;
}
.t1-stale-msg { font-size: 13px; color: #ffd9a8; margin-bottom: 12px; }

.tier1-divider {
  display: flex; align-items: center; text-align: center;
  color: var(--muted); font-size: 12px; margin: 18px 0 14px;
}
.tier1-divider::before, .tier1-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.tier1-divider span { padding: 0 12px; }

/* ---- Inline Tier-2 edit panel ---- */
.edit-panel { margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.edit-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.edit-input {
  width: 100%; resize: vertical; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.edit-input:focus { border-color: var(--blurple); box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.22); }
.edit-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }

/* The review checkpoint — deliberately distinct: "here's exactly what changes". */
.edit-review {
  margin-top: 16px; padding: 16px;
  border: 1px solid var(--blurple); border-radius: 12px;
  background: rgba(88, 101, 242, 0.06);
}
.review-nochange { color: var(--muted); font-size: 14px; }
.review-block { margin-bottom: 14px; }
.review-title {
  font-size: 11.5px; font-weight: 700; color: var(--blurple);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}
.review-diff, .review-readback {
  margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.55; color: #cdd2e6;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; white-space: pre-wrap; overflow-x: auto;
}
.edit-confirm-actions { margin-top: 4px; }

/* ---- Toggle switch ---- */
.switch { position: relative; display: inline-block; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; transition: background .2s ease;
}
.slider::before {
  content: ""; position: absolute; height: 17px; width: 17px; left: 3px; top: 3px;
  background: var(--muted); border-radius: 50%; transition: transform .2s ease, background .2s ease;
}
.switch input:checked + .slider { background: rgba(59, 165, 93, 0.25); border-color: var(--green); }
.switch input:checked + .slider::before { transform: translateX(19px); background: var(--green); }

/* ---- Entry animation: a freshly created rule separates into the list ---- */
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.rule-card.new { animation: dropIn .45s cubic-bezier(.2, .8, .2, 1); }
.rule-card.flash { box-shadow: 0 0 0 2px var(--blurple), var(--shadow); }
.rule-card.removing { animation: dropIn .25s reverse forwards; }
