/* =============================================================
   Apex Admin Console — styles
============================================================= */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --primary: #4f7cff;
  --primary-hover: #3f6bef;
  --green: #2ecc71;
  --red: #ff5c5c;
  --amber: #f5a623;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: #262b36; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(255, 92, 92, 0.12); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.icon-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 0.25rem 0.5rem; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- Login ---- */
.login-screen, .splash {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.splash { flex-direction: column; gap: 1rem; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem; width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand h1 { margin: 0.6rem 0 0.2rem; font-size: 1.4rem; }
.login-logo {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto;
  background: linear-gradient(135deg, var(--primary), #7a5cff);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.5rem; color: #fff;
}
.login-logo.small { width: 32px; height: 32px; font-size: 1rem; border-radius: 9px; }
.login-card label { display: block; font-size: 0.82rem; color: var(--muted); margin: 0.8rem 0 0.35rem; }
input, select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 0.6rem 0.75rem; font-size: 0.9rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--red); font-size: 0.85rem; margin: 0.8rem 0 0; }
.login-hint { text-align: center; margin-top: 1.2rem; font-size: 0.78rem; }
.login-form-mt { margin-top: 1.2rem; }

/* ---- App shell ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1.5rem; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.topbar-right { display: flex; align-items: center; gap: 0.9rem; }
.content { max-width: 1150px; margin: 0 auto; padding: 1.5rem; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.page-head h2 { margin: 0 0 0.2rem; }
.page-actions { display: flex; gap: 0.6rem; align-items: center; }
.search { width: 240px; }

/* ---- Org cards ---- */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem;
}
.org-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.org-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.org-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.org-card-head h3 { margin: 0; font-size: 1.05rem; }
.org-meta { display: flex; gap: 1.2rem; margin-top: 0.9rem; }
.org-meta .num { font-size: 1.15rem; font-weight: 700; }
.org-meta .lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.org-card-foot { margin-top: 0.9rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px;
  border: 1px solid var(--border); text-transform: capitalize;
}
.badge.dot::before { content: "●"; font-size: 0.6rem; }
.badge-green { color: var(--green); border-color: rgba(46,204,113,0.4); background: rgba(46,204,113,0.08); }
.badge-red   { color: var(--red);   border-color: rgba(255,92,92,0.4);  background: rgba(255,92,92,0.08); }
.badge-amber { color: var(--amber); border-color: rgba(245,166,35,0.4); background: rgba(245,166,35,0.08); }
.badge-gray  { color: var(--muted); }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 3rem 1rem; z-index: 20; overflow-y: auto;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 560px; box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.3rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.3rem; }

/* ---- Forms in modal ---- */
.field { margin-bottom: 0.9rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.field-row { display: flex; gap: 0.8rem; }
.field-row .field { flex: 1; }
.check-row { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.6rem; cursor: pointer; }
.check-row input { width: auto; }
.check-row span { font-size: 0.9rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }
.form-err { color: var(--red); font-size: 0.85rem; margin: 0.3rem 0 0; }

/* ---- Unified production field table (Features tab) ---- */
.field-table-wrap { border: 1px solid var(--border); border-radius: 12px; }
.field-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 560px; }
.field-table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border);
}
.field-table td { padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.field-table tr:last-child td { border-bottom: none; }
.field-table td input[type="text"], .field-table td input[type="number"], .field-table td select {
  width: 100%; margin: 0; padding: 0.4rem 0.5rem; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 0.86rem;
}
.field-table td input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }
.field-table td:first-child, .field-table td:nth-child(2),
.field-table td:nth-child(6), .field-table td:last-child { text-align: center; }

/* ---- Full-screen org detail ---- */
.org-detail-body { max-width: 1040px; margin: 0 auto; }
#org-detail-screen .brand strong { font-size: 1.05rem; }

/* Hero: identity + active state, always visible */
.od-hero {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.2rem 1.4rem; box-shadow: var(--shadow);
  display: flex; gap: 1.4rem; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; margin-bottom: 1.2rem;
}
.od-hero-main { flex: 1 1 340px; min-width: 260px; }
.od-name-row { display: flex; gap: 0.6rem; align-items: flex-end; }
.od-name-row .field { flex: 1; margin: 0; min-width: 0; }
.od-name-row button { flex: 0 0 auto; }
.od-hero-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.9rem; }
.od-chip {
  font-size: 0.76rem; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); padding: 0.22rem 0.6rem; border-radius: 999px;
}
.od-active {
  display: flex; align-items: center; gap: 1rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 0.65rem 0.9rem;
}
.od-active.on { border-color: rgba(46, 204, 113, 0.45); }
.od-active-title { font-weight: 600; font-size: 0.92rem; }

/* Tabbed body: left nav + one focused panel */
.od-tabs { display: grid; grid-template-columns: 190px 1fr; gap: 1.2rem; align-items: start; }
.od-tabnav { display: flex; flex-direction: column; gap: 0.25rem; position: sticky; top: 1rem; }
.od-tabnav button {
  text-align: left; padding: 0.6rem 0.85rem; border-radius: 10px; font-family: inherit;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  cursor: pointer; font-size: 0.9rem;
}
.od-tabnav button:hover { background: var(--surface); color: var(--text); }
.od-tabnav button.active {
  background: var(--surface); color: var(--text); border-color: var(--border); font-weight: 600;
}
.od-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.2rem 1.4rem; box-shadow: var(--shadow);
}
.od-panel.hidden { display: none; }
.od-panel > .section { margin-top: 0; }

@media (max-width: 760px) {
  .od-hero { flex-direction: column; }
  .od-hero-main { flex: 0 0 auto; width: 100%; }
  .od-active { width: 100%; justify-content: space-between; }
  .od-tabs { grid-template-columns: 1fr; }
  .od-tabnav {
    flex-direction: row; overflow-x: auto; position: static; padding-bottom: 0.3rem; gap: 0.4rem;
  }
  .od-tabnav button { white-space: nowrap; flex: 0 0 auto; }
}

/* ---- Detail sections ---- */
.section { margin-top: 1.4rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.section-head h4 { margin: 0; font-size: 0.95rem; }
.kv { display: flex; gap: 0.5rem; font-size: 0.88rem; margin-bottom: 0.35rem; }
.kv .k { color: var(--muted); min-width: 90px; }

/* ---- Admin list rows ---- */
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.7rem 0.85rem; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 0.5rem; background: var(--surface-2);
}
.list-row .info { min-width: 0; }
.list-row .info .name { font-weight: 600; font-size: 0.92rem; }
.list-row .info .sub { color: var(--muted); font-size: 0.8rem; }
.row-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }
.empty { color: var(--muted); font-size: 0.88rem; padding: 0.6rem 0; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 0.7rem 1.1rem; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 40; font-size: 0.9rem; max-width: 90vw;
}
.toast.err { border-color: var(--red); color: #ffd4d4; }
.toast.ok { border-color: var(--green); }

/* ---- Toggle switch ---- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; cursor: pointer; transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: var(--muted); border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: rgba(46,204,113,0.25); border-color: var(--green); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--green); }
.switch input:disabled + .slider { opacity: 0.4; cursor: not-allowed; }

.loading-state { text-align: center; color: var(--muted); padding: 3rem 0; grid-column: 1 / -1; }

@media (max-width: 560px) {
  .field-row { flex-direction: column; gap: 0; }
  .search { width: 100%; }
  .page-actions { width: 100%; }
}
