:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafafc;
  --border: #e5e7ec;
  --border-strong: #d4d7de;
  --text: #0d0e12;
  --text-muted: #6b7280;
  --text-subtle: #9099a3;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --success: #16a34a;
  --warning: #d97706;
  --topbar-bg: #0c0d11;
  --topbar-fg: #f1f2f5;
  --topbar-fg-muted: #8a8d96;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 17, 21, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 17, 21, 0.06), 0 1px 2px rgba(15, 17, 21, 0.04);
  --shadow-lg: 0 12px 40px rgba(15, 17, 21, 0.18);
  --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.25);
  --transition: 120ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Topbar -------------------------------------------------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#topbar h1 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--topbar-fg);
}

#tabs {
  display: flex;
  gap: 2px;
  flex: 1;
}

#tabs button {
  background: transparent;
  border: 0;
  color: var(--topbar-fg-muted);
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
}

#tabs button:hover {
  color: var(--topbar-fg);
  background: rgba(255, 255, 255, 0.06);
}

#tabs button.active {
  color: var(--topbar-fg);
  background: rgba(255, 255, 255, 0.1);
}

#user-box {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  color: var(--topbar-fg-muted);
}

#user-email {
  font-weight: 500;
}

#logout-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--topbar-fg);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

#logout-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
}

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

button {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: var(--transition);
  line-height: 1.4;
}

button:hover {
  background: var(--surface-2);
  border-color: var(--text-subtle);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.danger {
  color: var(--danger);
  border-color: var(--border);
  background: var(--surface);
}

button.danger:hover {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}

button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* ---------- Main layout --------------------------------------------------- */

#main {
  padding: 28px;
  max-width: 1180px;
  margin: 0 auto;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 16px;
}

.view-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.view-header > span,
.view-header > .muted {
  color: var(--text-muted);
}

/* ---------- Cards / tables ----------------------------------------------- */

.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.grid th,
.grid td {
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.grid th {
  background: var(--surface-2);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  border-bottom-color: var(--border);
}

.grid tbody tr:hover {
  background: var(--surface-2);
}

.grid tbody tr:last-child td {
  border-bottom: 0;
}

.grid td code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.grid td .row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.grid td .row-actions button {
  padding: 5px 10px;
  font-size: 12.5px;
}

/* Empty-state row */
.grid td[colspan] {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 28px 16px;
}

/* ---------- Pills --------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.pill.success {
  background: rgba(22, 163, 74, 0.08);
  color: var(--success);
  border-color: rgba(22, 163, 74, 0.2);
}

.pill.muted {
  color: var(--text-subtle);
}

/* ---------- Login --------------------------------------------------------- */

#login-view {
  max-width: 380px;
  margin: 96px auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#login-form h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

#login-form input,
#dialog-form input:not([type="checkbox"]):not([type="file"]),
#dialog-form select,
#dialog-form textarea {
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

#login-form input:focus,
#dialog-form input:focus,
#dialog-form select:focus,
#dialog-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

#login-form button[type="submit"] {
  margin-top: 4px;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

#login-form button[type="submit"]:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--danger);
  margin: 0;
  font-size: 13px;
}

/* ---------- Dialog -------------------------------------------------------- */

#dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  max-width: 560px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
  background: var(--surface);
}

#dialog::backdrop {
  background: rgba(13, 14, 18, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#dialog-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#dialog-form h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

#dialog-form label.row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

#dialog-form textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  min-height: 144px;
  resize: vertical;
}

#dialog-form .row {
  display: flex;
  gap: 12px;
}

#dialog-form .row > * {
  flex: 1;
}

#dialog-form .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

#dialog-form input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

#dialog-form input[type="file"] {
  font-size: 13px;
}

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

#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--topbar-bg);
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  max-width: 360px;
  z-index: 50;
  animation: toast-in 180ms ease-out;
}

#toast.error {
  background: var(--danger);
}

#toast.ok {
  background: var(--success);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Utilities ----------------------------------------------------- */

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- Responsive ---------------------------------------------------- */

@media (max-width: 720px) {
  #topbar {
    padding: 12px 16px;
    gap: 12px;
  }
  #main {
    padding: 16px;
  }
  .view-header h2 {
    font-size: 18px;
  }
  .grid td,
  .grid th {
    padding: 10px 12px;
  }
  #dialog {
    max-width: calc(100% - 24px);
  }
  #dialog-form .row {
    flex-direction: column;
  }
}
