/* Canvas: shared tokens and UI pieces (dialogs, buttons, menus, toasts). */

:root {
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --canvas: #e7e9ee;
  --dot: #b3b9c6;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --ink: #1e1e22;
  --muted: #646b79;
  --line: #d6dae2;
  --accent: #3451d1;
  --accent-ink: #ffffff;
  --accent-soft: rgba(52, 81, 209, 0.12);
  --sel: #3451d1;
  --sel-wash: rgba(52, 81, 209, 0.32);
  --gridline: rgba(30, 40, 70, 0.07);
  --danger: #d42a2a;
  --ok: #2f9e44;
  --warn: #e8890c;
  --link-bg: #ffffff;
  --overlay: rgba(22, 26, 38, 0.42);
  --shadow-sm: 0 1px 2px rgba(20, 24, 36, 0.1);
  --shadow: 0 1px 3px rgba(20, 24, 36, 0.08), 0 10px 30px -6px rgba(20, 24, 36, 0.22);
  --radius: 10px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --canvas: #16171b;
  --dot: #34373f;
  --panel: #23252b;
  --panel-2: #2c2f36;
  --ink: #ececee;
  --muted: #9da3ae;
  --line: #3a3d46;
  --accent: #8098ff;
  --accent-ink: #11152a;
  --accent-soft: rgba(128, 152, 255, 0.16);
  --sel: #8098ff;
  --sel-wash: rgba(128, 152, 255, 0.38);
  --gridline: rgba(255, 255, 255, 0.05);
  --danger: #ff6b6b;
  --ok: #51cf66;
  --warn: #fcc419;
  --link-bg: #2c2f36;
  --overlay: rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 12px 32px -6px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:hover {
  background: var(--panel-2);
}
.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover {
  filter: brightness(1.07);
}
.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn.danger-text {
  color: var(--danger);
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
}
.btn.ghost:hover {
  background: var(--panel-2);
}
.btn.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13.5px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--panel-2);
}
.icon-btn svg,
.ico {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.pill-btn {
  height: 34px;
  max-width: 160px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.pill-btn:hover {
  filter: brightness(0.97);
}

/* ---------- dialogs ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--overlay);
  animation: fade-in 0.12s ease-out;
}

.dlg {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 22px 22px 18px;
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  animation: rise 0.16s ease-out;
}
.dlg-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.dlg-text,
.dlg-note {
  margin: 0 0 14px;
  color: var(--muted);
}
.dlg-note {
  font-size: 13.5px;
  margin-top: 4px;
}
.field {
  display: block;
  margin: 12px 0;
}
.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 13.5px;
  font-weight: 550;
}
.field-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}
.field input,
.login-form input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 16px; /* 16px keeps iOS from zooming in */
}
.field input[type="file"] {
  height: auto;
  padding: 8px;
  font-size: 14px;
}
.field input:focus,
.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.dlg-error,
.form-error {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 14px;
}
.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- context menu ---------- */

.menu {
  position: fixed;
  z-index: 60;
  min-width: 210px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  animation: fade-in 0.08s ease-out;
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--accent-soft);
  outline: none;
}
.menu-item.danger {
  color: var(--danger);
}
.menu-item.checked .menu-label::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 8px 1px 0;
  border-radius: 50%;
  background: var(--accent);
}
.menu-kbd {
  color: var(--muted);
  font-size: 12.5px;
}
.menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--line);
}
@media (pointer: coarse) {
  .menu-item {
    padding: 11px 12px;
    font-size: 15px;
  }
  .menu-kbd {
    display: none;
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 120;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--canvas);
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s, transform 0.16s;
}
.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}
.toast.error {
  background: var(--danger);
  color: #fff;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

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