/* ==========================================================================
   Latent Database

   Supabase Studio's dark interface: its neutral scale (#171717 / #1c1c1c /
   #232323 / #2e2e2e), its #3ECF8E brand green used sparingly, small radii,
   1px borders everywhere, dense data tables, fixed sidebar.

   Dark is the default. A light override lives under [data-theme="light"] and
   is toggled from the sidebar; dark being the CSS default means there is no
   flash of the wrong theme before the script runs.
   ========================================================================== */

:root {
  /* Supabase dark neutrals */
  --bg:          #1c1c1c;   /* studio surface */
  --bg-sunk:     #171717;   /* deeper: page behind panels, table headers */
  --bg-raised:   #1c1c1c;   /* panels */
  --bg-hover:    #232323;   /* row hover, ghost button hover */
  --bg-control:  #2e2e2e;   /* default button face */

  --line:        #2e2e2e;   /* default border */
  --line-strong: #3e3e3e;   /* input border, stronger dividers */

  --ink:         #ededed;   /* foreground */
  --ink-2:       #a0a0a0;   /* foreground-light */
  --ink-3:       #707070;   /* foreground-lighter */

  --accent:      #3ecf8e;   /* brand */
  --accent-hi:   #4ade9b;   /* brand hover */
  --accent-ink:  #171717;   /* text on a brand-filled button */
  --accent-weak: #1a2c23;   /* brand-tinted surface */
  --accent-line: #2b5f45;

  --danger:      #f36c60;
  --danger-weak: #2a1a19;
  --danger-line: #5c2b27;

  --warn:        #f5c26b;
  --warn-weak:   #2a2318;
  --warn-line:   #5c4a26;

  --shadow:      rgba(0, 0, 0, .5);

  --r:    4px;
  --r-lg: 6px;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --side-w: 232px;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:          #ffffff;
  --bg-sunk:     #fbfbfa;
  --bg-raised:   #ffffff;
  --bg-hover:    #f6f6f5;
  --bg-control:  #ffffff;

  --line:        #e6e6e3;
  --line-strong: #d4d4d0;

  --ink:         #1c1c1a;
  --ink-2:       #5a5a55;
  --ink-3:       #8b8b84;

  --accent:      #1a7f52;
  --accent-hi:   #14663f;
  --accent-ink:  #ffffff;
  --accent-weak: #eaf5ee;
  --accent-line: #bcdfcc;

  --danger:      #a32c1e;
  --danger-weak: #fbeeec;
  --danger-line: #edc9c3;

  --warn:        #7a5312;
  --warn-weak:   #fdf5e6;
  --warn-line:   #ecd9ae;

  --shadow:      rgba(20, 20, 18, .16);

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-sunk);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--accent); color: var(--accent-ink); }

/* Supabase's scrollbars stay dark rather than reverting to the OS default. */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-sunk); }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* --------------------------------------------------------------------------
   Sign in
   -------------------------------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 20px;
  background: var(--bg-sunk);
}

.auth__panel {
  width: 100%;
  max-width: 400px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 36px 34px 32px;
}

.auth__logo {
  height: 34px;
  width: auto;
  display: block;
  margin-bottom: 26px;
}

.auth__title {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.auth__sub {
  margin: 0 0 24px;
  color: var(--ink-2);
  font-size: 13px;
}

.auth__form { display: flex; flex-direction: column; gap: 16px; }
.auth__actions { display: flex; gap: 10px; }

.auth__foot {
  margin: 0;
  color: var(--ink-3);
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   Fields
   -------------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; }

.field__label {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--ink-2);
}

.field__input,
.field__select {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg-sunk);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  color: var(--ink);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}

.field__input::placeholder { color: var(--ink-3); }

.field__input:focus,
.field__select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.field__hint { font-size: 12px; color: var(--ink-3); }

.field--row { flex-direction: row; align-items: center; gap: 9px; }
.field--row .field__label { color: var(--ink); }

input[type="checkbox"] { accent-color: var(--accent); }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--bg-control);
  color: var(--ink);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}

.btn:hover { background: var(--bg-hover); border-color: var(--ink-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
}
.btn--primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }

.btn--danger { color: var(--danger); border-color: var(--danger-line); background: transparent; }
.btn--danger:hover { background: var(--danger-weak); border-color: var(--danger); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--bg-hover); border-color: var(--line); color: var(--ink); }

.btn--block { width: 100%; }
.btn--sm { padding: 4px 9px; font-size: 12.5px; }

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.side {
  width: var(--side-w);
  flex: 0 0 var(--side-w);
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.side__brand {
  display: block;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line);
}
.side__brand img { height: 24px; width: auto; display: block; }

.side__nav { padding: 12px; flex: 1; overflow-y: auto; }

.side__link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  margin-bottom: 1px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
}
.side__link:hover { background: var(--bg-hover); color: var(--ink); }
.side__link.is-active {
  background: var(--bg-hover);
  border-color: var(--line-strong);
  color: var(--ink);
}

.side__group { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.side__heading {
  margin: 0 0 5px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--ink-3);
}

.side__foot { padding: 13px 16px; border-top: 1px solid var(--line); }
.side__who  { margin: 0; font-size: 12.5px; color: var(--ink); overflow-wrap: anywhere; }
.side__role { margin: 1px 0 9px; font-size: 12px; color: var(--ink-3); }

.side__tools { display: flex; align-items: center; gap: 12px; }

.side__signout, .side__theme {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 12.5px;
  cursor: pointer;
}
.side__signout { text-decoration: underline; text-underline-offset: 2px; }
.side__signout:hover, .side__theme:hover { color: var(--ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-sunk); }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 26px 17px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar__title {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.topbar__sub { margin: 3px 0 0; color: var(--ink-2); font-size: 13px; }
.topbar__actions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

.content { padding: 22px 26px 60px; flex: 1; }

/* --------------------------------------------------------------------------
   Data table
   -------------------------------------------------------------------------- */

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.panel + .panel { margin-top: 20px; }

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.panel__title { margin: 0; font-size: 14px; font-weight: 500; }
.panel__note  { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-3); }
.panel__body  { padding: 16px; }

.table { width: 100%; border-collapse: collapse; }

.table th {
  text-align: left;
  padding: 8px 16px;
  background: var(--bg-sunk);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-2);
  white-space: nowrap;
}

.table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 13px;
}

.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-hover); }

.table__mono { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.table__num  { text-align: right; font-variant-numeric: tabular-nums; }
.table__act  { text-align: right; white-space: nowrap; }

.table--click tbody tr { cursor: pointer; }

.muted { color: var(--ink-3); }
.strong { font-weight: 500; color: var(--ink); }

/* State is a word, not a coloured pill. */
.state { font-size: 12.5px; color: var(--ink-2); }
.state--off  { color: var(--ink-3); }
.state--bad  { color: var(--danger); }
.state--warn { color: var(--warn); }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.empty__title { margin: 0 0 4px; color: var(--ink); font-weight: 500; }

/* --------------------------------------------------------------------------
   Notices
   -------------------------------------------------------------------------- */

.notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg-sunk);
  font-size: 13px;
  color: var(--ink-2);
}

.notice--error { background: var(--danger-weak); border-color: var(--danger-line); color: var(--danger); }
.notice--warn  { background: var(--warn-weak);  border-color: var(--warn-line);  color: var(--warn); }
.notice--ok    { background: var(--accent-weak); border-color: var(--accent-line); color: var(--accent); }

.notice ul { margin: 6px 0 0; padding-left: 18px; }
.notice li { margin: 2px 0; }

/* --------------------------------------------------------------------------
   Toolbar / pagination
   -------------------------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar .field__input { width: 300px; max-width: 100%; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-2);
}

.pager__buttons { display: flex; gap: 8px; }

/* --------------------------------------------------------------------------
   Stats
   -------------------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: 20px;
}

.stat { background: var(--bg-raised); padding: 14px 16px; }
.stat__n { font-size: 22px; font-weight: 500; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat__k { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; }
.stat--bad  .stat__n { color: var(--danger); }
.stat--warn .stat__n { color: var(--warn); }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }

.modal__panel {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px var(--shadow);
}

.modal__panel--wide { max-width: 860px; }

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.modal__title { margin: 0; font-size: 15px; font-weight: 500; }

.modal__close {
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  padding: 0 4px;
}
.modal__close:hover { color: var(--ink); }

.modal__body { padding: 20px; overflow-y: auto; }
.modal__form { display: flex; flex-direction: column; gap: 15px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 4px; }

/* --------------------------------------------------------------------------
   Import wizard
   -------------------------------------------------------------------------- */

.steps { display: flex; gap: 6px; margin-bottom: 20px; font-size: 12.5px; color: var(--ink-3); }
.steps span { padding-bottom: 7px; border-bottom: 2px solid transparent; }
.steps .is-on { color: var(--ink); border-bottom-color: var(--accent); }
.steps i { font-style: normal; opacity: .4; }

.drop {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  padding: 34px 20px;
  text-align: center;
  background: var(--bg-sunk);
}
.drop.is-over { border-color: var(--accent); background: var(--accent-weak); }
.drop__hint { margin: 6px 0 14px; color: var(--ink-3); font-size: 12.5px; }
.drop input[type="file"] { color: var(--ink-2); font-size: 12.5px; }

.map { width: 100%; border-collapse: collapse; }
.map th, .map td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.map th { font-size: 12px; font-weight: 400; color: var(--ink-2); background: var(--bg-sunk); }
.map select {
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--bg-sunk);
  color: var(--ink);
}
.map__sample { font-family: var(--mono); font-size: 12px; color: var(--ink-3); overflow-wrap: anywhere; }

.scroll-x { overflow-x: auto; }

details > summary { color: var(--ink-2); }
details > summary:hover { color: var(--ink); }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: 380px;
  padding: 11px 15px;
  background: var(--bg-control);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: var(--r);
  font-size: 13px;
  box-shadow: 0 10px 30px var(--shadow);
}
.toast--bad { border-color: var(--danger-line); color: var(--danger); }

/* --------------------------------------------------------------------------
   Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .side {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side__nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side__link { width: auto; }
  .side__group { width: 100%; margin-top: 10px; padding-top: 10px; }
  .side__foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .side__role { display: none; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
  .toolbar .field__input { width: 100%; }
}
