/* ==========================================================================
   Exhibition Wall Planner by Storitellah — styles
   Mobile-first, gallery-inspired, dark & light themes.
   ========================================================================== */

:root {
  --accent: #d4af37;
  --accent-ink: #1a1508;
  --danger: #c0504d;
  --radius: 10px;
  --radius-sm: 6px;
  --panel-w: 340px;
  --header-h: 56px;
  --mobilebar-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
}

body[data-theme="dark"] {
  --bg: #121218;
  --bg-2: #1a1a22;
  --bg-3: #22222c;
  --line: #2e2e3a;
  --ink: #eceae4;
  --ink-2: #a7a5a0;
  --ink-3: #6f6e6c;
  --viewport-bg: #0c0c11;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
body[data-theme="light"] {
  --bg: #faf9f6;
  --bg-2: #ffffff;
  --bg-3: #f0eee8;
  --line: #ddd9d0;
  --ink: #23221f;
  --ink-2: #6b6963;
  --ink-3: #9c9a93;
  --viewport-bg: #e7e4dc;
  --shadow: 0 6px 24px rgba(30, 28, 20, .14);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 1rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink); margin-bottom: 12px; font-weight: 700; }
h3 { font-size: .78rem; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-2); margin: 18px 0 10px; font-weight: 600; }
.hint { font-size: .78rem; color: var(--ink-2); line-height: 1.45; margin: 8px 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: .75rem; font-weight: 400; color: var(--ink-2); }
.ic { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; fill: none; }
.ic.big { width: 34px; height: 34px; }

/* ============ HEADER ============ */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: calc(var(--header-h) + var(--sat));
  padding: var(--sat) max(14px, var(--sar)) 0 max(14px, var(--sal));
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: none;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand h1 { font-size: 1rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .by { font-weight: 400; color: var(--ink-2); font-size: .85rem; }
.header-clock {
  margin-left: auto;
  text-align: right;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#clockTime { font-size: .95rem; font-weight: 600; letter-spacing: .03em; }
.clock-sub { display: block; font-size: .68rem; color: var(--ink-2); }
.header-actions { display: flex; gap: 8px; align-items: center; flex: none; }

body[data-theme="dark"] .ic-sun { display: block; }
body[data-theme="dark"] .ic-moon { display: none; }
body[data-theme="light"] .ic-sun { display: none; }
body[data-theme="light"] .ic-moon { display: block; }

/* ============ BUTTONS / INPUTS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  font-size: .85rem;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: .75rem; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.icon-btn { padding: 8px; min-width: 40px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid .btn-danger { grid-column: 1 / -1; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.linklike { color: var(--accent); text-decoration: underline; font: inherit; }

.field { display: block; margin-bottom: 12px; min-width: 0; }
.field > span { display: block; font-size: .74rem; letter-spacing: .03em; color: var(--ink-2); margin-bottom: 5px; }
.field > span em { font-style: normal; color: var(--ink-3); }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--ink);
  font-size: .9rem;
}
.field textarea { resize: vertical; line-height: 1.4; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.color-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.color-field input[type="color"] {
  width: 46px; height: 38px; padding: 2px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-2); cursor: pointer;
}
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); }
.swatches button:hover { border-color: var(--accent); }

.toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-bottom: 12px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: .82rem; min-height: 34px; cursor: pointer; color: var(--ink); }
.toggle input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { flex: 1; min-height: 38px; font-size: .8rem; background: var(--bg-2); color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ============ LAYOUT ============ */
.app-main { flex: 1; display: flex; min-height: 0; position: relative; }

.panel {
  width: var(--panel-w);
  flex: none;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  transition: margin-left .25s ease;
}
.panel.collapsed { margin-left: calc(-1 * var(--panel-w)); }
.panel-collapse {
  position: absolute;
  right: -18px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 64px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--ink-2);
  z-index: 5;
  font-size: 14px;
}
.panel.collapsed .panel-collapse::before { content: "›"; }
.panel.collapsed .panel-collapse { color: transparent; }
.panel.collapsed .panel-collapse::before { color: var(--ink-2); position: absolute; inset: 0; display: grid; place-items: center; }

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex: none;
  overflow-x: auto;
  scrollbar-width: none;
}
.panel-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  min-height: 44px;
  padding: 0 10px;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-page { display: none; padding: 16px 16px calc(24px + var(--sab)); overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.tab-page.active { display: block; }
.empty-note { text-align: center; padding: 34px 10px; color: var(--ink-2); }

/* ============ DROPZONE + LIBRARY ============ */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 14px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 14px;
}
.dropzone strong { color: var(--ink); font-size: .9rem; }
.dropzone span { font-size: .74rem; }
.dropzone .privacy-note { color: var(--accent); }
.dropzone.dragover, .dropzone:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }

.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
.lib-item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-3);
  cursor: pointer;
  -webkit-user-drag: element;
}
.lib-item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; pointer-events: none; }
.lib-item .lib-name { display: block; font-size: .62rem; padding: 4px 5px 2px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .lib-dims { display: block; font-size: .6rem; padding: 0 5px 4px; color: var(--ink-3); }
.lib-item .lib-remove {
  position: absolute; top: 3px; right: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  display: grid; place-items: center;
}
.lib-item.placed::after {
  content: "on wall";
  position: absolute; left: 3px; top: 3px;
  font-size: .55rem;
  background: var(--accent); color: var(--accent-ink);
  padding: 1px 5px; border-radius: 99px; font-weight: 700;
}

.text-list { display: flex; flex-direction: column; gap: 6px; }
.text-list .text-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: .8rem; cursor: pointer;
}
.text-list .text-row:hover { border-color: var(--accent); }
.text-list .text-row .tt { color: var(--ink-3); font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; flex: none; }
.text-list .text-row .th { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ EXPORT CARDS / SUPPORT ============ */
.export-card, .support-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--bg-2);
}
.export-card h3 { margin-top: 0; }
.support-card p { font-size: .8rem; color: var(--ink-2); line-height: 1.5; margin-bottom: 12px; }
.support-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  color: var(--ink);
}
.support-link:hover { border-color: var(--accent); text-decoration: none; }
.support-link strong { display: block; font-size: .85rem; }
.support-link em { display: block; font-style: normal; font-size: .72rem; color: var(--ink-2); }
.support-ic {
  width: 34px; height: 34px; flex: none;
  border-radius: 8px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #fff;
}
.support-ic.patreon { background: #ff424d; }
.support-ic.kofi { background: #13c3ff; }
.support-ic.mpesa { background: #43b02a; }
.mpesa-line { cursor: default; }
.mpesa-line .btn { margin-left: auto; }

/* ============ CANVAS AREA ============ */
.canvas-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex: none;
  scrollbar-width: none;
}
.canvas-toolbar::-webkit-scrollbar { display: none; }
.tool-group { display: flex; align-items: center; gap: 2px; padding: 0 8px; border-right: 1px solid var(--line); flex: none; }
.tool-group:first-child { padding-left: 0; }
.tool-group:last-child { border-right: none; }
.zoom-group { margin-left: auto; }
.tbtn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
}
.tbtn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.6; fill: currentColor; }
.tbtn svg [fill="none"], .tbtn svg path[d^="M"] { fill: none; }
.tbtn svg rect:not([fill="none"]) { stroke: none; }
.tbtn:hover:not(:disabled) { background: var(--bg-3); color: var(--ink); }
.tbtn:disabled { opacity: .32; cursor: default; }
.tbtn.zoom-label { width: auto; padding: 0 10px; font-size: .78rem; font-weight: 600; }
.gap-field { display: flex; align-items: center; gap: 4px; font-size: .72rem; color: var(--ink-2); }
.gap-field input {
  width: 58px; min-height: 34px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--ink);
  font-size: .8rem;
}

.viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--viewport-bg);
  touch-action: none;
  cursor: default;
}
.wall-stage { position: absolute; transform-origin: 0 0; }
.wall {
  position: relative;
  box-shadow: var(--shadow);
  outline: 1px solid rgba(0, 0, 0, .18);
}
.wall-guides, .wall-overlay { position: absolute; inset: 0; pointer-events: none; }
.wall-items { position: absolute; inset: 0; }
.wall-overlay { z-index: 60; }

.floor {
  position: absolute;
  left: -6%; right: -6%;
  height: 26px;
  background: linear-gradient(rgba(0,0,0,.28), rgba(0,0,0,.08));
  border-top: 2px solid rgba(0,0,0,.5);
  display: none;
}
.floor.on { display: block; }
.wall-dims {
  position: absolute;
  color: var(--ink-2);
  font-size: calc(13px * var(--inv, 1));
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* guide lines drawn as positioned divs (sized in JS) */
.gline { position: absolute; pointer-events: none; }
.gline.center-v { border-left: 1px dashed color-mix(in srgb, var(--accent) 75%, transparent); top: 0; bottom: 0; width: 0; }
.gline.eye { border-top: 1px dashed rgba(200, 60, 60, .75); left: 0; right: 0; height: 0; }
.gline.eye::after {
  content: "eye level";
  position: absolute;
  right: 4px;
  top: calc(-15px * var(--inv, 1));
  font-size: calc(10px * var(--inv, 1));
  color: rgba(200, 60, 60, .9);
  letter-spacing: .05em;
}
.gline.safe { border: 1px dashed rgba(120, 160, 220, .65); }
.grid-layer { position: absolute; inset: 0; }

/* ============ WALL ITEMS ============ */
.witem {
  position: absolute;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.witem .frame-box {
  position: absolute; inset: 0;
  box-shadow: 1px 3px 8px rgba(0,0,0,.35);
}
.witem .mat-box { position: absolute; background: #f8f6f0; }
.witem .img-box { position: absolute; overflow: hidden; background: #d8d4ca; display: flex; align-items: center; justify-content: center; }
.witem .img-box img { width: 100%; height: 100%; display: block; pointer-events: none; }
.witem .img-box.mode-crop img { object-fit: cover; }
.witem .img-box.mode-fit img { object-fit: contain; }
.witem .wall-caption {
  position: absolute;
  top: 100%; left: 0;
  padding-top: 4px;
  color: rgba(0,0,0,.72);
  pointer-events: none;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  max-width: 200%;
}
.witem .wall-caption .cap-t { font-weight: 600; }
.witem .wall-caption .cap-s { opacity: .75; }
.wall.dark-wall .witem .wall-caption { color: rgba(255,255,255,.82); }

.witem.text-item .text-box {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-start;
  overflow: hidden;
  line-height: 1.25;
}
.witem.text-item .text-box .t-head { font-family: var(--font-serif); font-weight: 700; letter-spacing: .01em; }
.witem.text-item .text-box .t-body { font-family: var(--font); opacity: .85; white-space: pre-wrap; }

.witem.selected { z-index: 55 !important; }
.witem .sel-ring {
  position: absolute;
  inset: calc(-3px * var(--inv, 1));
  border: calc(2px * var(--inv, 1)) solid var(--accent);
  border-radius: 2px;
  display: none;
  pointer-events: none;
}
.witem.selected .sel-ring { display: block; }
.witem.grouped .sel-ring { border-style: dashed; }

.handle {
  position: absolute;
  width: calc(30px * var(--inv, 1));
  height: calc(30px * var(--inv, 1));
  right: calc(-17px * var(--inv, 1));
  bottom: calc(-17px * var(--inv, 1));
  display: none;
  place-items: center;
  cursor: nwse-resize;
  touch-action: none;
  z-index: 2;
}
.handle::after {
  content: "";
  width: calc(15px * var(--inv, 1));
  height: calc(15px * var(--inv, 1));
  background: var(--accent);
  border: calc(2px * var(--inv, 1)) solid var(--bg);
  border-radius: 50%;
  display: block;
}
.witem.selected.primary .handle { display: grid; }

/* alignment guides + measurement labels */
.smart-line { position: absolute; background: #e2554f; pointer-events: none; z-index: 70; }
.smart-line.v { width: calc(1.5px * var(--inv, 1)); }
.smart-line.h { height: calc(1.5px * var(--inv, 1)); }
.measure-tag {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: calc(10px * var(--inv, 1));
  padding: calc(1px * var(--inv, 1)) calc(5px * var(--inv, 1));
  border-radius: 3px;
  background: rgba(20, 20, 26, .82);
  color: #ffd97a;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 70;
  white-space: nowrap;
}
.marquee {
  position: absolute;
  border: 1px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  pointer-events: none;
  z-index: 80;
}

.empty-wall-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  color: var(--ink-2);
  pointer-events: none;
  padding: 20px;
}
.empty-wall-hint p { pointer-events: auto; font-size: .95rem; }
.empty-wall-hint[hidden] { display: none; }

/* ============ FOOTER / TOAST ============ */
.app-footer {
  flex: none;
  text-align: center;
  font-size: .78rem;
  padding: 8px 12px calc(8px + var(--sab));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink-2);
}
.footer-sub { font-size: .68rem; margin-top: 2px; color: var(--ink-3); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--sab));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 99px;
  font-size: .84rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ MOBILE ============ */
.mobile-bar { display: none; }

@media (max-width: 860px) {
  :root { --header-h: 50px; }
  .brand h1 { font-size: .86rem; }
  .brand .by { display: none; }
  .header-clock { line-height: 1.05; }
  #clockTime { font-size: .82rem; }
  .clock-sub { font-size: .6rem; }
  #btnLoadDemo, #btnHeaderExport { display: none; }

  .app-main { flex-direction: column-reverse; }
  .app-footer { display: none; }

  .mobile-bar {
    display: flex;
    flex: none;
    background: var(--bg-2);
    border-top: 1px solid var(--line);
    padding-bottom: var(--sab);
    z-index: 60;
  }
  .mobile-bar button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 2px 6px;
    font-size: .62rem;
    color: var(--ink-2);
    min-height: var(--mobilebar-h);
  }
  .mobile-bar button svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.7; fill: none; }
  .mobile-bar button.active { color: var(--accent); }

  .panel {
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--line);
    height: 46dvh;
    transition: height .22s ease;
    order: -1;
  }
  .panel.sheet-hidden { height: 0; border-top: none; overflow: hidden; }
  .panel-collapse { display: none; }
  .panel-tabs { display: none; }
  .tab-page { padding: 14px 14px 20px; }

  .canvas-area { flex: 1; min-height: 0; }
  .canvas-toolbar { padding: 4px 6px; }
  .tbtn { width: 42px; height: 42px; }

  .field-row { grid-template-columns: 1fr 1fr; }
  .btn { min-height: 44px; }
  .library { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
}

@media (max-width: 500px) {
  .toggle-grid { grid-template-columns: 1fr 1fr; }
  .btn-grid { grid-template-columns: 1fr 1fr; }
}

/* landscape phones: shorter sheet */
@media (max-width: 940px) and (max-height: 500px) {
  .panel { height: 62dvh; }
}

@media print {
  body { display: none; }
}
