:root{
  --bg: #0b0f14;
  --panel: #121822;
  --text: #e6eef7;
  --muted: #9fb0c7;
  --primary: #3ea6ff;
  --danger: #ff5d5d;
  /* Archive (amber) variant - dark theme */
  --archive: #ffd37a;       /* accent */
  --archive-ink: #ffd37a;   /* text color */
  --archive-bg: #2a210a;    /* background */
  --archive-border: #4a3a12;/* border */
  --chip-bg: #1b2532;
  --ok: #29c96b;
  --border: #1f2a3a;
  --panel-alt: #0c121c;
  /* Annotator paddings (tweakable) */
  --annot-pad-top: 12px;
  --annot-pad-side: 12px;
  --annot-pad-bottom: 96px; /* leave ample room above bottom toolbar / orange line */
  --annot-toolbar-space: 140px; /* reserve space so image ends above toolbars */
}

:root[data-theme="light"]{
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #0b0f14;
  --muted: #556171;
  --primary: #3ea6ff;
  --danger: #cc2e33;
  /* Archive (amber) variant - light theme */
  --archive: #ffd37a;       /* accent */
  --archive-ink: #6a4300;   /* text color */
  --archive-bg: #fff5e6;    /* background */
  --archive-border: #ffd37a;/* border */
  --chip-bg: #eef3f9;
  --ok: #1e8e4a;
  --border: #d9e1ea;
  --panel-alt: #f4f7fb;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
/* Avoid iOS auto text scaling side effects */
html{ -webkit-text-size-adjust: 100%; }

.app-bar{
  position: sticky; top: 0; z-index: 10;
  display:flex; align-items:center; justify-content:space-between;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}
.app-bar h1{margin:0;font-size:20px;letter-spacing:0.4px}
.app-actions{display:flex;gap:8px;align-items:center}
.app-actions a, .app-actions button{color:var(--text)}

.container{max-width:1000px;margin:0 auto;padding:16px}

.controls{display:flex;flex-direction:column;gap:10px;margin-bottom:12px}
.filter-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.actions-row{display:flex;gap:8px}

input, select, button{
  font: inherit;
  color: var(--text);
}
input, select{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
/* Prevent iOS Safari zoom on focus: ensure form controls use >=16px */
input, select, textarea { font-size: 16px; }
/* iOS-targeted reinforcement to override UA styles */
@supports (-webkit-touch-callout: none) {
  input, select, textarea { font-size: 16px !important; }
}
input:focus, select:focus{border-color: var(--primary); box-shadow: 0 0 0 3px #3ea6ff22}

/* Smart search with clear button */
.search-input-wrap{ position: relative; width: 100%; }
.search-input-wrap input{ width: 100%; padding-right: 36px; }
/* Custom clear button inside input; shown when wrapper has data-has-value="1" */
.search-input-wrap .clear-input{ position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: transparent; border: none; padding: 0; width: 24px; height: 24px; color: var(--muted); cursor: pointer; display: none; z-index: 3; line-height: 1; }
.search-input-wrap .clear-input:hover{ color: var(--text); }
.search-input-wrap .clear-input:focus-visible{ outline: none; box-shadow: 0 0 0 3px #3ea6ff22; border-radius: 999px; }
.search-input-wrap[data-has-value="1"] .clear-input{ display: inline-flex; align-items: center; justify-content: center; }
/* Hide native WebKit clear so only our button shows for consistent look */
input[type="search"]::-webkit-search-cancel-button{ -webkit-appearance: none; }

button{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary{background: var(--primary); border-color: var(--primary); color:#04121f}
button.ghost{background: transparent}
button.danger{background: #2a1010; border-color:#482222; color:#ffb5b5}
/* Archive (amber) button variant */
button.archive{
  background: var(--archive-bg);
  border-color: var(--archive-border);
  color: var(--archive-ink);
}
button.archive:hover{ filter: brightness(1.06) }
button.archive:focus-visible{
  outline: none;
  /* Fallback for browsers without color-mix */
  box-shadow: 0 0 0 3px rgba(255, 211, 122, 0.35);
  /* Prefer dynamic mix when supported */
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--archive) 30%, transparent);
}
button:active{transform: translateY(1px)}

.sheet{background: var(--panel-alt); border:1px solid var(--border); border-radius:12px; padding:12px}
.hidden{display:none}

.job-form .form-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap:12px;
}
.job-form label{display:flex;flex-direction:column;gap:6px}
.job-form label span{color:var(--muted);font-size:12px}
.form-actions{margin-top:12px;display:flex;gap:8px;justify-content:flex-end}

.upload-progress{position:relative;height:12px;background:#0a111b;border:1px solid #1f2a3a;border-radius:999px;overflow:hidden;margin-top:10px}
.upload-progress .bar{position:absolute;inset:0 100% 0 0;background:linear-gradient(90deg, #2d7dd2, #3ea6ff);transition:width .15s ease}
.upload-progress .label{position:absolute;right:8px;top:50%;transform:translateY(-50%);font-size:11px;color:var(--muted)}

.cards{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap:12px;
}
.jobs-status{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  min-height:52px;
  margin-bottom:12px;
  color:var(--muted);
}
.jobs-status.error{color:#ffb5b5}
.dashboard-status{
  padding:10px 12px;
  margin-bottom:12px;
  border:1px solid var(--border);
  border-radius:8px;
  color:var(--muted);
}
.dashboard-status.error{border-color:#6b2a2a;color:#ffb5b5}
.jobs-status[hidden], .dashboard-status[hidden], #appNotice[hidden]{display:none}
#appNotice{
  position:fixed;
  right:16px;
  bottom:calc(16px + env(safe-area-inset-bottom));
  z-index:1000010;
  max-width:min(420px, calc(100vw - 32px));
  padding:10px 14px;
  border:1px solid var(--border);
  border-radius:10px;
  background:var(--panel);
  color:var(--text);
  box-shadow:0 8px 28px rgba(0,0,0,.35);
}
#appNotice.error{border-color:#6b2a2a;color:#ffb5b5}
.card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display:flex;flex-direction:column;gap:10px;
}
/* Content area inside card gets status tint and edges */
.card .card-content{ background: transparent; border-radius: 10px; padding: 10px; border-left: 4px solid transparent; border-right: 4px solid transparent; transition: background-color .15s ease, border-color .15s ease }
/* Dark theme defaults for status tints */
.card .card-content.status-bg-not-started{ background: #121821; border-left-color: #3a485a }
.card .card-content.status-bg-mixed-paint{ background: #14162a; border-left-color: #6aa4ff }
.card .card-content.status-bg-completed-painting{ background: #0d1c21; border-left-color: #2cb1bf }
.card .card-content.status-bg-fully-completed{ background: #0f1d13; border-left-color: #3fb36d }
/* Right edge due warnings */
.card .card-content.due-edge-soon{ border-right-color: #ffd666 }
.card .card-content.due-edge-today{ border-right-color: #ffb020 }
.card .card-content.due-edge-overdue{ border-right-color: #f44336 }
/* Light theme overrides for softer tints */
:root[data-theme="light"] .card .card-content.status-bg-not-started{ background:#f6f7f9; border-left-color:#cfd4dc }
:root[data-theme="light"] .card .card-content.status-bg-mixed-paint{ background:#e8f3ff; border-left-color:#84b7ff }
:root[data-theme="light"] .card .card-content.status-bg-completed-painting{ background:#e6f6f8; border-left-color:#53cdda }
:root[data-theme="light"] .card .card-content.status-bg-fully-completed{ background:#eafaf0; border-left-color:#66cd8a }
/* Splide carousel styling to match previous look */
.splide{position:relative;border-radius:10px;border:1px solid var(--border);background:var(--panel-alt);overflow:hidden}
.splide__slide img{width:100%;height:180px;object-fit:cover;display:block}
.splide__arrow{background:#0008;border:1px solid var(--border);color:var(--text)}
.splide__pagination__page{background: var(--muted)}
.splide__pagination__page.is-active{background: var(--primary)}
.notes{white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word}
.title{display:flex;gap:8px;align-items:center}
.title .price{font-weight:700;font-size:18px}
.due-alert{
  background: #e691da;
  color: #0b0f14;
  padding: 2px 6px;
  border-radius: 6px;
  display: inline-block;
}
.status-chip{
  margin-left:auto;
  padding: 4px 8px;
  background: var(--chip-bg);
  border-radius: 999px;
  font-size: 12px; color: var(--muted);
}
.card-row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.card-row.meta{color:var(--muted);font-size:14px;gap:16px}
.card-row.notes-wrap{align-items: flex-start}
.card-row.actions{
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.card-row.actions select{
  flex: 1 1 220px;
  min-width: 180px;
}
.card-row.actions .action-buttons{
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.card-row.actions .action-buttons button{
  flex: 0 0 auto;
}
@media (max-width: 560px){
  .card-row.actions select{
    flex-basis: 100%;
    min-width: 0;
  }
  .card-row.actions .action-buttons{
    width: 100%;
    margin-left: 0;
  }
}
.status-tabs{display:flex;gap:6px;align-items:center;flex-wrap:wrap;border-bottom:1px solid var(--border);padding-bottom:6px}
.status-tabs .tab{
  background: transparent;
  border: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 12px;
  color: var(--muted);
}
.status-tabs .tab:hover{color: var(--text); background: var(--panel-alt)}
.status-tabs .tab.active{
  color: var(--text);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-bottom-color: transparent;
}

/* Status coloring */
.st-not-started{background:#2a2f3a;color:#c9d4e6}
.st-mixed-paint{background:#2b2942;color:#cbbcff}
.st-completed-painting{background:#1f3a44;color:#bceff5}
.st-fully-completed{background:#1f2f20;color:#bff0c8; border:1px solid #2a5f34}

/* Narrow screens */
@media (max-width: 480px) {
  .order-filter{margin-left:auto}
}

/* Lightbox */
.lightbox{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:#000c;z-index:1000;padding:20px}
.lightbox.hidden{display:none}
.lightbox img{max-width:95vw;max-height:90vh;border-radius:10px;box-shadow:0 10px 40px #0008}
.lightbox .lb-close{position:absolute;top:16px;right:16px;background:#000a;border:1px solid #223044;color:var(--text)}

/* Thumbnails grid in edit form */
.thumbs-block { display: contents; }
.thumbs-title { align-self: end; color: var(--muted); font-size: 12px; }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; align-items: start; }
.thumb { position: relative; width: 100%; padding-top: 100%; background: var(--panel-alt); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .trash { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text); opacity: 0; transition: opacity .15s ease; }
.thumb .trash { grid-auto-flow: column; gap: 8px; }
.thumb .trash button { background: rgba(0,0,0,0.5); border: 1px solid var(--border); color: var(--text); border-radius: 999px; width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer; }
.thumb:hover .trash, .thumb:focus-within .trash { opacity: 1; }
/* Always show controls for newly selected images */
#newImagesBlock .trash { opacity: 1; }
/* On touch devices, make overlays visible */
@media (hover: none) {
  .thumb .trash { opacity: 1; }
}

/* Placeholder when no photo */
.no-photo{
  height: 180px;
  display: grid;
  place-items: center;
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 14px;
}
/* Position marker.js2 over the image inside our overlay */
#annotatorOverlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000000; padding: 0; }
/* Constrain the editor to an inner box with safe-area padding so toolbars stay visible */
#annotatorOverlay .inner {
  position: relative;
  /* Use dynamic viewport units to avoid mobile URL bar issues */
  width: 96vw; /* fallback for older browsers */
  width: min(96vw, 96dvw);
  height: 92vh; /* fallback for older browsers */
  height: min(92svh, 92dvh);
  /* Leave room around edges and respect notches/home indicator. 
     Bottom padding tuned so the image ends near the orange line. */
  padding:
    calc(env(safe-area-inset-top) + var(--annot-pad-top))
    calc(env(safe-area-inset-right) + var(--annot-pad-side))
    calc(env(safe-area-inset-bottom) + var(--annot-pad-bottom))
    calc(env(safe-area-inset-left) + var(--annot-pad-side));
  display: grid; place-items: center; z-index: 1;
  background: transparent;
}
#annotatorOverlay .annot-img {
  max-width: 100%;
  /* Keep image above toolbars by reserving bottom space */
  max-height: calc(100% - var(--annot-toolbar-space));
  height: auto; width: auto;
  display: block;
  pointer-events: none;
}
#annotatorOverlay .close-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.6); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 6px 10px; cursor: pointer;
  z-index: 3; pointer-events: auto;
}
/* Ensure marker.js2 stack is above overlay background but inside the inner box */
.markerjs2-container, .markerjs2 { z-index: 1000001 !important; }

/* Dashboard */
.summary-header{font-weight:700;color:var(--muted)}
.stats-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;margin-bottom:12px}
.stat-card{display:flex;flex-direction:column;gap:4px}
.stat-label{color:var(--muted);font-size:13px}
.stat-value{font-weight:800;font-size:24px}
.stat-sub{color:var(--muted);font-size:12px}

/* Chart */
.chart-card{overflow:hidden; grid-column: 1 / -1}
.chart{width:100%; height:220px;}
.chart canvas, .chart svg{display:block;width:100%;height:100%}
.chart .grid line{stroke:var(--border);stroke-width:1;opacity:.6}
.chart .axis{stroke:var(--border);stroke-width:1}
.chart .path{fill:none;stroke:#49a6ff;stroke-width:2.5}
.chart .point{fill:#49a6ff}
.chart .label{fill:var(--muted);font-size:11px}

/* (debug table removed) */

/* Login */
.login{display:grid;place-items:center;min-height:100vh}
.login .card{background:var(--panel);border:1px solid var(--border);border-radius:12px;padding:20px;width:min(90%,360px);box-shadow:0 6px 24px rgba(0,0,0,.35)}
.login .card h2{margin:0 0 12px 0;font-weight:600;letter-spacing:.2px}
.login form{display:flex;flex-direction:column;gap:12px}
.login label{display:flex;flex-direction:column;gap:6px;color:var(--muted)}
.login input{background:var(--panel-alt)}
.login .err{color:#ffb5b5;margin:0 0 8px 0}
.offline-card{text-align:center}
.offline-card img{border-radius:20%;margin:0 auto 12px}
