/* ExtraCP control panel — dark, professional admin theme.
   Committed dark look (per design guidance): deep slate surfaces, blue primary
   actions, green for positive status. All long values wrap so nothing spills
   out of a card. */

:root {
  --bg: #020617;
  --surface: #0b1220;
  --surface-2: #0f1930;
  --inset: #0c1526;
  --border: #24304a;
  --border-soft: #1a2338;
  --text: #e9eef7;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2f6fe0;
  --on-primary: #ffffff;
  --ok: #22c55e;
  --danger: #f87171;
  --danger-hover: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 34px rgba(0, 0, 0, .45);
  --ring: 0 0 0 3px rgba(59, 130, 246, .45);
  --space: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { max-width: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, h4 { line-height: 1.25; }
a { color: var(--primary); text-decoration: none; overflow-wrap: anywhere; }
a:hover { text-decoration: underline; }

/* Data-bearing text always wraps rather than overflowing its container. */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); }

/* Focus visibility for keyboard users. */
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

/* ---------- Buttons & inputs ---------- */
button { font-family: inherit; }
button, .btn-sm, .btn-file {
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease, opacity .18s ease;
}
input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
}
input::placeholder { color: #64748b; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--primary); box-shadow: var(--ring);
}

/* Primary action button (login, create). */
button[type="submit"], #login-btn, #create-btn, #editor-save {
  border: none;
  border-radius: var(--radius-sm);
  padding: .65rem 1.1rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-primary);
}
button[type="submit"]:hover, #editor-save:hover { background: var(--primary-hover); }
button:disabled { opacity: .55; cursor: default; }

/* Small secondary buttons (toolbars). */
.btn-sm, .btn-file {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: .45rem .8rem;
  font-size: .85rem;
  font-weight: 600;
  display: inline-block;
}
.btn-sm:hover, .btn-file:hover { border-color: var(--primary); }

/* Text/link buttons used inside table rows. */
.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }
.link.danger:hover { color: var(--danger-hover); }

/* ---------- Login ---------- */
.view { min-height: 100dvh; }
#login-view { display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.brand { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.subtitle { margin: .25rem 0 1.4rem; color: var(--muted); font-size: .95rem; }
.card label { font-size: .82rem; font-weight: 600; margin-bottom: .35rem; }
.card input { margin-bottom: 1rem; }
#login-error { margin: .25rem 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.25rem;
  background: rgba(11, 18, 32, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-size: 1.15rem; }
.topbar nav { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.whoami { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }

/* ---------- Dashboard layout ---------- */
.dash { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.dash h2 { margin: .25rem 0 .25rem; font-size: 1.5rem; }

/* Shared card surface for every panel section. */
.sys-card, .acct-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-top: 1.25rem;
  overflow-wrap: anywhere;
}
.sys-card h3, .acct-card h3 { margin: 0 0 .9rem; font-size: 1.02rem; }
.sys-row { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
#exec-detail { margin: .55rem 0 0; overflow-wrap: anywhere; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  border-radius: 999px; padding: .18rem .6rem; border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-ok { color: #4ade80; border-color: rgba(74, 222, 128, .5); background: rgba(34, 197, 94, .1); }
.badge-bad { color: var(--danger); border-color: rgba(248, 113, 113, .5); background: rgba(248, 113, 113, .1); }
.badge-wait { color: var(--muted); }

/* ---------- Create-account form ---------- */
.create-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.create-form .field { display: flex; flex-direction: column; min-width: 140px; }
.create-form .field.grow { flex: 1; min-width: 200px; }
.create-form label { font-size: .78rem; margin-bottom: .3rem; color: var(--muted); }
.create-form input, .create-form select { padding: .5rem .6rem; }
#create-error { margin: .6rem 0 0; }

/* ---------- Tables (scroll horizontally on small screens) ---------- */
.table-scroll { width: 100%; overflow-x: auto; margin-top: 1rem; }
.acct-table, .fm-table {
  width: 100%; border-collapse: collapse; font-size: .92rem;
}
.acct-table th, .acct-table td, .fm-table th, .fm-table td {
  text-align: left; padding: .6rem .6rem; border-bottom: 1px solid var(--border-soft);
  vertical-align: top; overflow-wrap: anywhere;
}
.acct-table th, .fm-table th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  position: sticky; top: 0; background: var(--surface);
}
.row-actions { display: flex; flex-wrap: wrap; gap: .3rem .7rem; justify-content: flex-end; }
.row-actions .link { white-space: nowrap; }

.nav-stub { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.nav-stub li {
  padding: .5rem .8rem; background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); color: var(--muted); font-size: .85rem;
}
.soon {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: .05rem .45rem; margin-left: .4rem;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: rgba(2, 6, 23, .66);
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: min(820px, 96vw);
  max-height: 90dvh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  padding: 1rem 1.15rem; border-bottom: 1px solid var(--border);
}
.modal-head strong { overflow-wrap: anywhere; }
.breadcrumb { font-size: .82rem; margin-top: .35rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .15rem .3rem; }
.breadcrumb .link { font-size: .82rem; font-weight: 500; }

.fm-toolbar { display: flex; gap: .5rem; align-items: center; padding: .8rem 1.15rem; flex-wrap: wrap; }
.fm-msg { font-size: .84rem; color: var(--muted); overflow-wrap: anywhere; }
.fm-msg.error { color: var(--danger); }
.fm-prompt { padding: .4rem .55rem; min-width: 0; }

/* File-manager table scrolls inside the modal body. */
.db-body { overflow: auto; }
.fm-box > .table-scroll { overflow: auto; padding: 0 1.15rem 1.15rem; max-height: 60dvh; }
.fm-table th { background: var(--surface); }

/* Editor */
.editor-box { max-width: min(820px, 96vw); }
#editor-text {
  flex: 1; min-height: 320px; margin: 1rem 1.15rem; padding: .75rem;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem;
  border-radius: var(--radius-sm); resize: vertical;
}
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: .75rem; padding: 0 1.15rem 1.15rem; }

/* Databases + HTTPS + Customer modal bodies */
.db-body { padding: 0 1.15rem 1.2rem; }
.db-body h4 { margin: 1.1rem 0 .45rem; font-size: .95rem; }
.db-body .fm-toolbar { padding: .35rem 0; }
.db-secret {
  background: rgba(59, 130, 246, .1); border: 1px solid rgba(59, 130, 246, .5);
  border-radius: var(--radius-sm); padding: .85rem 1rem; margin-top: 1rem; font-size: .9rem;
  overflow-wrap: anywhere;
}
.db-secret .creds { margin-top: .55rem; line-height: 1.8; }
.db-secret code, .db-body code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--inset); padding: .12rem .4rem; border-radius: 5px; overflow-wrap: anywhere;
}

.mono {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .82rem; overflow-wrap: anywhere;
}

.backup-codes { display: flex; flex-wrap: wrap; gap: .4rem .6rem; }
.backup-codes code { font-size: .95rem; letter-spacing: .5px; }

.rs-packages { display: flex; flex-wrap: wrap; gap: .35rem .9rem; align-items: center; }
.rs-pkg { display: inline-flex; align-items: center; gap: .3rem; font-size: .9rem; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Narrow screens: stack the create form controls full width. */
@media (max-width: 560px) {
  .create-form .field, .create-form .field.grow { flex: 1 1 100%; min-width: 0; }
  .create-form button[type="submit"] { width: 100%; }
  .row-actions { justify-content: flex-start; }
}
