/* ============ Design tokens ============ */
:root {
  --bg-0: #0b0e14;
  --bg-1: #111621;
  --bg-2: #171d2b;
  --bg-3: #1f2739;
  --border: #2a3247;
  --border-strong: #3a4560;
  --text: #e5e9f0;
  --text-dim: #a2acc0;
  --muted: #6b7690;
  --accent: #5b9dff;
  --accent-hover: #77aeff;
  --accent-quiet: rgba(91, 157, 255, 0.15);
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --emd: #f59e0b;
  --mirror: #60a5fa;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg-0);
}
input, button, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.dim { color: var(--text-dim); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.hidden { display: none !important; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }

/* ============ Boot / loading ============ */
.boot-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}

/* ============ Login page ============ */
.page-login {
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(91,157,255,0.08), transparent),
    var(--bg-0);
}
.login-shell {
  min-height: 100vh;
  display: grid; place-items: center; padding: 24px;
}
.login-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 32px 28px;
  width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.login-header h1 { margin: 0 0 6px 0; font-size: 22px; font-weight: 600; }
.login-header p { margin: 0 0 20px 0; }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form label { font-size: 12px; color: var(--muted); margin-bottom: -4px; }
.login-form input {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; color: var(--text);
  transition: border-color 0.12s;
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 4px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer; font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: #262f45; border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: rgba(248,113,113,0.35); }
.btn-danger:hover { background: rgba(248,113,113,0.1); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-2); border-color: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn-group { display: inline-flex; gap: 6px; }

/* ============ Inputs ============ */
input[type=text], input[type=password], input[type=url], input[type=number],
input[type=email], select, textarea {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text);
  width: 100%; font: inherit;
  transition: border-color 0.12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; min-height: 80px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.field-row-3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr 1fr; }
.checkbox {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 13px; color: var(--text);
}
.checkbox input { width: auto; margin: 0; }

/* ============ App layout ============ */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 0;
}
.sidebar .brand {
  padding: 0 20px 20px;
  font-size: 16px; font-weight: 700; letter-spacing: 0.02em;
}
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  color: var(--muted); text-decoration: none;
  padding: 10px 20px; font-size: 14px;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.sidebar nav a:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.sidebar nav a.active {
  color: var(--text);
  background: var(--accent-quiet);
  border-left-color: var(--accent);
}
.sidebar .spacer { flex: 1; }
.sidebar .logout {
  margin: 0 20px;
  padding: 8px 12px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
}
.sidebar .logout:hover { color: var(--text); border-color: var(--border-strong); }

.view { padding: 24px 32px; overflow: auto; min-width: 0; }
.view-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 16px;
}
.view-header h1 { margin: 0; font-size: 20px; font-weight: 600; }

/* ============ Card ============ */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.card-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-header .subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-empty { color: var(--muted); font-style: italic; padding: 16px 0; text-align: center; }

/* ============ Table ============ */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th {
  color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
td.actions { text-align: right; white-space: nowrap; }

/* ============ Badges ============ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500;
  background: var(--bg-3); color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge-good { background: rgba(52,211,153,0.15); color: var(--good); border-color: rgba(52,211,153,0.3); }
.badge-bad  { background: rgba(248,113,113,0.15); color: var(--bad); border-color: rgba(248,113,113,0.3); }
.badge-warn { background: rgba(251,191,36,0.15); color: var(--warn); border-color: rgba(251,191,36,0.3); }
.badge-emd  { background: rgba(245,158,11,0.15); color: var(--emd); border-color: rgba(245,158,11,0.3); }
.badge-mirror { background: rgba(96,165,250,0.15); color: var(--mirror); border-color: rgba(96,165,250,0.3); }
.badge-auto { background: rgba(107,118,144,0.15); color: var(--muted); }

/* ============ Sites list ============ */
.sites-toolbar {
  display: flex; gap: 12px; margin-bottom: 20px; align-items: center;
}
.sites-toolbar input[type=text] { flex: 1; max-width: 400px; }

.sites-table td { vertical-align: top; }
.site-name { font-weight: 600; }
.site-name.emd { color: var(--text); }
.site-name.standalone { color: var(--text); }
.site-name a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
.site-name a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.mirror-arrow { color: var(--muted); margin-right: 6px; font-family: ui-monospace, monospace; }
.mirror-row td:first-child { padding-left: 32px; }
.mirror-row .site-name { font-weight: 400; color: var(--text-dim); }

.group-separator td {
  border-top: 1px solid var(--border-strong);
  padding-top: 0; padding-bottom: 0; height: 4px;
}

.site-meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ Workspace ============ */
.ws-header {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.ws-header h1 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.ws-header .meta { font-size: 12px; color: var(--muted); }
.ws-header .meta a { color: var(--accent); text-decoration: none; }
.ws-header .meta a:hover { text-decoration: underline; }

.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 16px; cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 14px; font-weight: 500;
  transition: color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--text-dim); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge { margin-left: 6px; }
.tab.disabled { color: var(--muted); opacity: 0.4; cursor: not-allowed; }

/* ============ Files editor ============ */
.files-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; height: calc(100vh - 240px); min-height: 400px; }
.file-tree {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.file-tree-header {
  padding: 10px 12px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.file-tree-actions { display: flex; gap: 4px; }
.file-list { flex: 1; overflow: auto; padding: 4px; }
.file-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 8px; border-radius: 4px; cursor: pointer;
  font-size: 13px; color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.file-item:hover { background: rgba(255,255,255,0.03); color: var(--text); }
.file-item.active { background: var(--accent-quiet); color: var(--accent); }
.file-item .del { opacity: 0; color: var(--bad); font-size: 14px; padding: 0 4px; }
.file-item:hover .del { opacity: 0.7; }
.file-item .del:hover { opacity: 1; }

.editor-pane {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.editor-tab {
  padding: 8px 14px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.editor-tab .status { font-size: 11px; }
.editor-tab .status.dirty { color: var(--warn); }
.editor-tab .status.saved { color: var(--good); }
.monaco-holder { flex: 1; min-height: 0; }

.binary-preview {
  padding: 40px; text-align: center; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  height: 100%; justify-content: center;
}
.binary-preview img {
  max-width: 100%; max-height: 300px;
  border-radius: 4px; border: 1px solid var(--border);
}

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: grid; place-items: center; z-index: 100;
  padding: 20px;
  animation: fade-in 0.15s;
}
.modal {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 100%; max-width: 520px;
  max-height: 85vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.15s;
}
.modal.wide { max-width: 720px; }
.modal h2 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.modal .modal-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid var(--border);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ============ Toast ============ */
#toast-root {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-width: 240px; max-width: 360px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: slide-in 0.2s;
  font-size: 13px;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
@keyframes slide-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ============ Deploy log ============ */
.deploy-log {
  background: #05070c;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; line-height: 1.4;
  white-space: pre-wrap; word-break: break-all;
  max-height: 400px; overflow: auto;
  color: #cbd5e1;
}

/* ============ Language subfolders form (matches user's reference) ============ */
.subfolder-form-grid {
  display: grid;
  grid-template-columns: 120px 100px 80px 1fr 32px;
  gap: 10px;
  align-items: start;
}
.subfolder-form-grid.wide {
  grid-template-columns: 1fr 100px 80px 1.4fr 1.8fr auto;
}
.subfolder-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  background: var(--bg-2);
}
.subfolder-row.inactive { opacity: 0.55; }
.subfolder-row .row-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.subfolder-row .row-header .url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--text-dim);
}
.subfolder-row .row-header .row-actions { display: flex; gap: 6px; }

/* ============ Redirects list ============ */
.redirect-row {
  display: grid;
  grid-template-columns: 1fr auto 2fr auto 60px auto;
  gap: 10px; align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--bg-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.redirect-row .arrow { color: var(--muted); }
.redirect-row .status-code {
  padding: 2px 6px; border-radius: 4px;
  background: var(--accent-quiet); color: var(--accent);
  font-size: 11px; text-align: center;
}
.redirect-row.auto { background: rgba(107,118,144,0.05); }

/* ============ Link ============ */
a.link { color: var(--accent); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* ============ Responsive tweaks ============ */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; padding: 12px; overflow-x: auto; }
  .sidebar .brand { padding: 0 12px; }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a { border-left: none; border-bottom: 2px solid transparent; padding: 6px 12px; }
  .sidebar nav a.active { border-left: none; border-bottom-color: var(--accent); }
  .sidebar .spacer, .sidebar .logout { display: none; }
  .files-layout { grid-template-columns: 1fr; height: auto; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
}
