:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #1d2422;
  --ink-2: #57605c;
  --ink-3: #8a918d;
  --line: #e2ddd3;
  --accent: #0f6b62;
  --accent-ink: #ffffff;
  --accent-soft: #e1efec;
  --danger: #b4332b;
  --danger-soft: #f8e5e3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(29 36 34 / 0.06), 0 4px 16px rgb(29 36 34 / 0.05);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141917;
    --surface: #1c2220;
    --surface-2: #232b28;
    --ink: #e8ece9;
    --ink-2: #a9b2ae;
    --ink-3: #78827d;
    --line: #2f3835;
    --accent: #4fb8a9;
    --accent-ink: #0b1513;
    --accent-soft: #1d3330;
    --danger: #ef7d74;
    --danger-soft: #3a2220;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.2);
    color-scheme: dark;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* ---------- Buttons & forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 14px; }
.btn-icon { padding: 0; width: 38px; }
.btn-sm.btn-icon { width: 32px; }

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

label { display: grid; align-content: start; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }

input, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.4 var(--font);
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.form-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* ---------- Layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, calc((100% - 960px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font: 600 19px var(--font-display);
  text-decoration: none;
}
.brand svg { width: 28px; height: 28px; color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
#current-user { margin-right: 6px; font-size: 14px; }

main.page { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: min(380px, 100%); padding: 32px 28px; }
.auth-card .brand { margin-bottom: 28px; }
.auth-card h1 { font: 600 26px var(--font-display); margin-bottom: 4px; }
.auth-card p { margin: 0 0 20px; }

/* ---------- Customer list ---------- */

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.search { position: relative; flex: 1; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; translate: 0 -50%; color: var(--ink-3); pointer-events: none; }
.search input { min-height: 44px; padding-left: 40px; font-size: 16px; }
.toolbar .btn { min-height: 44px; }

.customer-list { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.customer-list li + li { border-top: 1px solid var(--line); }
.customer-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  color: inherit;
  text-decoration: none;
}
.customer-row:hover { background: var(--surface-2); }
.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.02em;
}
.customer-name { font-weight: 600; font-size: 16px; }
.customer-name mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; }
.customer-sub { font-size: 13px; color: var(--ink-2); }
.customer-updated { font-size: 13px; color: var(--ink-3); text-align: right; }

.empty { padding: 48px 24px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- Customer page ---------- */

.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 16px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--ink); }
.back-link svg { width: 16px; height: 16px; }

.customer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.customer-header h1 { font: 600 32px var(--font-display); }
.customer-header p { margin: 4px 0 0; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 32px 0 12px; }
.section-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); }

.new-consultation { padding: 20px; }
.new-consultation .form-row { grid-template-columns: 180px 1fr; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-weight: 500;
  text-align: center;
  cursor: pointer;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone svg { width: 24px; height: 24px; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.previews { display: flex; flex-wrap: wrap; gap: 8px; }
.previews figure { position: relative; margin: 0; }
.previews img { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius-sm); }
.previews button {
  position: absolute; top: -6px; right: -6px;
  display: grid; place-items: center;
  width: 22px; height: 22px; padding: 0;
  border: none; border-radius: 50%;
  background: var(--ink); color: var(--bg);
  cursor: pointer;
}
.previews button svg { width: 14px; height: 14px; }

.consultations { display: grid; gap: 14px; }
.consultation { padding: 16px 20px 20px; }
.consultation.dragging { outline: 2px dashed var(--accent); outline-offset: -2px; }
.consultation-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.consultation-head h3 { font: 600 19px var(--font-display); }
.consultation-head .actions { display: flex; gap: 2px; }
.consultation .notes { margin: 10px 0 0; white-space: pre-wrap; }
.consultation .no-photos { margin: 10px 0 0; font-size: 14px; color: var(--ink-3); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.photo-grid button {
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
}
.photo-grid img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 0.25s; }
.photo-grid button:hover img { transform: scale(1.04); }

/* ---------- Dialogs ---------- */

dialog {
  width: min(460px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgb(0 0 0 / 0.25);
}
dialog::backdrop { background: rgb(20 25 23 / 0.45); backdrop-filter: blur(2px); }
dialog h2 { font: 600 22px var(--font-display); margin-bottom: 16px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dialog-head h2 { margin: 0; }

.user-list { list-style: none; margin: 0 0 20px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.user-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 8px 14px; min-height: 48px; }
.user-list li + li { border-top: 1px solid var(--line); }
.tag { padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.settings-separator { margin: 24px 0 20px; border: none; border-top: 1px solid var(--line); }
.settings-section-title { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); }

dialog.lightbox {
  width: 100vw;
  max-width: none;
  height: 100vh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: rgb(10 12 11 / 0.94);
  color: #fff;
}
.lightbox[open] { display: grid; grid-template-rows: auto 1fr; }
.lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; }
.lightbox-bar .btn { color: #e8ece9; }
.lightbox-bar .btn:hover { background: rgb(255 255 255 / 0.12); color: #fff; }
.lightbox-bar .btn-danger { color: #ff9b93; }
.lightbox-stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 0 64px 24px; }
.lightbox-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.lightbox-nav {
  position: absolute; top: 50%; translate: 0 -50%;
  width: 48px; height: 48px;
  border: none; border-radius: 50%;
  background: rgb(255 255 255 / 0.12); color: #fff;
  cursor: pointer;
}
.lightbox-nav:hover { background: rgb(255 255 255 / 0.22); }
.lightbox-nav svg { width: 24px; height: 24px; }
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100;
  translate: -50% 0;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink); color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .form-row, .new-consultation .form-row { grid-template-columns: 1fr; }
  .customer-row { grid-template-columns: auto 1fr; }
  .customer-updated { display: none; }
  .customer-header h1 { font-size: 26px; }
  #current-user, .toolbar .btn-label { display: none; }
  .lightbox-stage { padding: 0 8px 16px; }
  .lightbox-nav { bottom: 24px; top: auto; translate: none; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}
