/* ─── Design tokens ─────────────────────────────────────────────────── */
:root {
  --bg:          #0c0e13;
  --surface:     #13161d;
  --surface-2:   #1a1e28;
  --surface-3:   #222637;
  --border:      #252a38;
  --border-2:    #2e3449;
  --text:        #e2e6f0;
  --text-2:      #9aa3b8;
  --text-3:      #636d85;
  --accent:      #4f8cff;
  --accent-dim:  #1e3a6e;
  --green:       #3fb950;
  --green-dim:   #1a3a22;
  --red:         #e5534b;
  --red-dim:     #3a1a1a;
  --yellow:      #e3b341;
  --radius-sm:   4px;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
}

/* ─── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ─── Typography ─────────────────────────────────────────────────────── */
h1 { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
h2 { font-size: 18px; font-weight: 600; letter-spacing: -.2px; color: var(--text); }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase;
     letter-spacing: .06em; color: var(--text-3); margin-bottom: 14px; }
p  { color: var(--text-2); line-height: 1.65; margin-bottom: 10px; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; color: var(--text); }
code {
  font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
  font-size: 12.5px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

/* ─── Layout ─────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  margin-right: 32px;
  flex-shrink: 0;
}
.header-logo {
  width: 30px; height: 30px;
  border-radius: 7px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}
.header-brand span {
  font-size: 15px; font-weight: 700;
  color: var(--text); letter-spacing: -.2px;
}

nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}
nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: color .15s, background .15s;
}
nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--surface-3); }

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.header-user .user-email {
  font-size: 13px;
  color: var(--text-2);
}

main {
  flex: 1;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ─── Page header ────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 28px;
}
.page-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2 { margin: 0; }
.page-header .sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 18px;
}
.back-link:hover { color: var(--text-2); text-decoration: none; }
.back-link::before { content: "←"; }

/* ─── Card ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 { margin: 0; }
.card-body { padding: 22px; }
.card-body + .card-body { border-top: 1px solid var(--border); }

/* Compact card (no separate header/body) */
.card-plain { padding: 22px; }

/* ─── Project grid ───────────────────────────────────────────────────── */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.project-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  cursor: pointer;
}
.project-card:hover {
  border-color: var(--border-2);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  text-decoration: none;
}
.project-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.project-card-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.project-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}
.project-card-slug {
  font-size: 12px;
  color: var(--text-3);
  font-family: ui-monospace, monospace;
}
.project-card-meta {
  margin-top: auto;
  padding-top: 14px;
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 100px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red   { background: var(--red-dim);   color: var(--red);   }
.badge-blue  { background: var(--accent-dim); color: var(--accent); }
.badge-gray  { background: var(--surface-3);  color: var(--text-3); }

/* ─── Table ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  transition: background .1s;
}
tbody tr:hover { background: var(--surface-2); }
tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
tbody td:first-child { color: var(--text); font-weight: 500; }
tbody tr:last-child td { border-bottom: none; }

/* ─── Forms ──────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: span 1; } }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .01em;
}
.field .hint {
  font-size: 11.5px;
  color: var(--text-3);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="date"],
input[type="search"],
select.select {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="url"]:focus,
input[type="date"]:focus,
input[type="search"]:focus,
select.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.18);
}
input:disabled, textarea:disabled {
  opacity: .55;
  cursor: not-allowed;
  background: var(--surface);
}
select.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%239aa3b8' stroke-width='1.5'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

/* Checkboxes - consistent accent + size everywhere. */
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Column-structure table on the data-table management page. */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.data-table th { color: var(--text-3); font-weight: 500; }
.data-table td form { margin: 0; }

/* Vertical stack of form fields (row create/edit). */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 22px;
}

/* Page-header action buttons. */
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* "SQL" tag on ad-hoc (non-catalog) tables. */
.tag-sql {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--text-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: middle;
  font-family: ui-monospace, monospace;
}

/* Dynamic column builder (Create table). */
.column-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px auto auto 36px;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.column-row .cb {
  display: flex;
  gap: 7px;
  align-items: center;
  font-weight: 400;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}
.column-row [data-remove] { padding: 6px 9px; }
@media (max-width: 720px) {
  .column-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
  }
}

/* SQL console + JSON/edit textareas. */
textarea.sql-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}
textarea.sql-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.18);
}
.sql-output { margin-top: 16px; }
.sql-result { margin-bottom: 16px; }
.sql-status {
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
  color: var(--text-3);
  margin-bottom: 8px;
}

/* Row action buttons in the data browser. */
.row-actions { display: flex; gap: 8px; white-space: nowrap; }
.row-actions form { margin: 0; }

/* File input. */
.file-input {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}
.file-input::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

/* Storage media grid. */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.media-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
}
.media-thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-video { color: var(--text-2); font-size: 13px; font-weight: 600; }
.media-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 0;
  font-size: 12px;
  color: var(--text-3);
}
.media-actions {
  display: flex;
  gap: 6px;
  padding: 8px 10px 10px;
}
.media-actions form { margin: 0; }
input::placeholder { color: var(--text-3); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 0;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.checkbox-row span { font-size: 13.5px; color: var(--text-2); }

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: .88; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid #5a2020;
}
.btn-danger:hover { background: #4a1a1a; }

.btn-sm { padding: 5px 12px; font-size: 12.5px; }

.btn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* Legacy compat */
button { font-family: inherit; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
}
.link-btn:hover { color: var(--text-2); }

form.inline { display: inline; }

/* ─── Divider ────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}
.section-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
  margin: 28px 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── API key display ────────────────────────────────────────────────── */
.api-key-box {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
}
.api-key-box code {
  flex: 1;
  padding: 12px 14px;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: 13px;
  color: var(--accent);
  word-break: break-all;
  white-space: normal;
}
.api-key-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #2a1f00;
  border: 1px solid #5a3f00;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--yellow);
}
.api-key-warning::before { content: "⚠"; flex-shrink: 0; }

/* ─── Danger zone ────────────────────────────────────────────────────── */
.danger-zone {
  border: 1px solid #3a1a1a;
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}
.danger-zone-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  background: #1e1010;
  border-bottom: 1px solid #3a1a1a;
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  letter-spacing: .02em;
}
.danger-zone-header::before { content: "⚡"; }
.danger-zone-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid #2a1515;
}
.danger-zone-item:last-child { border-bottom: none; }
.danger-zone-item-info strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 2px;
}
.danger-zone-item-info p {
  font-size: 12.5px;
  color: var(--text-3);
  margin: 0;
}
.danger-confirm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.danger-confirm-row input {
  width: 200px;
  padding: 7px 11px;
  font-size: 13px;
}

/* ─── DB table list ──────────────────────────────────────────────────── */
.table-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.table-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.table-list-item:hover { border-color: var(--border-2); background: var(--surface-3); text-decoration: none; }
.table-list-item-name { font-size: 13px; font-weight: 500; color: var(--text); font-family: ui-monospace, monospace; }
.table-list-item-count { font-size: 12px; color: var(--text-3); flex-shrink: 0; }

/* ─── Stat row ───────────────────────────────────────────────────────── */
.stat-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 120px;
}
.stat-label { font-size: 11.5px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -.5px; }

/* ─── Pagination ─────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-3);
}

/* ─── Alert ──────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 20px;
}
.alert-error { background: var(--red-dim); border: 1px solid #5a2020; color: var(--red); }
.alert-success { background: var(--green-dim); border: 1px solid #1a4a22; color: var(--green); }
.alert-info { background: var(--accent-dim); border: 1px solid #1e4080; color: var(--accent); }

/* ─── Empty state ────────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
}
.empty-icon { font-size: 36px; margin-bottom: 14px; opacity: .5; }
.empty-state h3 { text-transform: none; letter-spacing: 0; color: var(--text-2); font-size: 15px; margin-bottom: 6px; }
.empty-state p { font-size: 13px; color: var(--text-3); max-width: 360px; margin: 0 auto; }

/* ─── Login page ─────────────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
}
.login-logo {
  width: 56px; height: 56px;
  border-radius: 14px;
  object-fit: contain;
  display: block;
  margin: 0 auto 20px;
}
.login-title { font-size: 20px; font-weight: 700; text-align: center; color: var(--text); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-3); text-align: center; margin-bottom: 28px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn-primary { width: 100%; margin-top: 8px; padding: 10px; font-size: 14px; }

/* ─── Monospace util ─────────────────────────────────────────────────── */
.mono { font-family: ui-monospace, "Cascadia Code", monospace; }
.muted { color: var(--text-3); font-size: 12.5px; }
