/* ==========================================================================
   Almera Mobile PWA — polished stylesheet
   Palette + typography lifted from almerateknik.com (dark theme).
   ========================================================================== */

/* Brand fonts — self-hosted, mirrored from almerateknik.com */
@font-face {
  font-family: "Neue Haas";
  src: url("assets/fonts/neueHaas-400.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Neue Haas";
  src: url("assets/fonts/neueHaas-500.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Neue Haas";
  src: url("assets/fonts/neueHaas-700.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Ethnocentric";
  src: url("assets/fonts/ethnocentric.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand gold — primary hsl(41 72% 58%) on almerateknik.com dark theme */
  --gold:        #e1b047;
  --gold-soft:   #e7bf6a;
  --gold-deep:   #b8871e;
  --gold-glow:   rgba(225, 176, 71, 0.28);

  /* Midnight navy base, matches the site's dark surface ramp */
  --bg-0:        #090e1a;      /* page base, deepest — hsl(222 47% 7%) */
  --bg-1:        #121826;      /* panels — hsl(222 36% 11%) */
  --bg-2:        #191f2e;      /* elevated surfaces — hsl(222 30% 14%) */
  --bg-3:        #22293a;      /* hover — hsl(222 26% 18%) */

  --line:        #2d3443;      /* hsl(222 20% 22%) */
  --line-soft:   #1e2434;

  --text:        #f4f0e7;      /* warm bone — hsl(42 36% 93%) */
  --text-dim:    #cec5b6;      /* hsl(38 20% 76%) */
  --text-mute:   #9f927f;      /* hsl(37 14% 56%) */
  --text-on-gold:#0f1526;      /* site theme_color, deep navy */

  --ok:          #5ecf96;
  --warn:        #e8b947;
  --danger:      #f06450;

  --brand-font:  "Ethnocentric", "Neue Haas", system-ui, sans-serif;
  --sans-font:   "Neue Haas", -apple-system, BlinkMacSystemFont, "SF Pro Text",
                 "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;

  --shadow-lg: 0 16px 48px rgba(0,0,0,0.55);
  --shadow:    0 8px 24px rgba(0,0,0,0.40);
  --shadow-sm: 0 2px 8px  rgba(0,0,0,0.30);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-lr:  env(safe-area-inset-left, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--sans-font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  text-rendering: optimizeLegibility;
}

/* Match almerateknik.com hero: cool navy glow top-left, warm gold glow top-right,
   deep well at the bottom — same radial-gradient stack the site uses. */
body {
  background:
    radial-gradient(ellipse at 0% -10%,
      rgba(41, 64, 122, 0.22) 0%, transparent 48%),
    radial-gradient(ellipse at 100% 0%,
      rgba(181, 140, 52, 0.14) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 100%,
      rgba(10, 18, 40, 0.5) 0%, transparent 60%),
    var(--bg-0);
  background-attachment: fixed;
}

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

/* Typography */
h1, h2, h3, h4 {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

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

/* ==========================================================================
   App shell
   ========================================================================== */
.app {
  min-height: 100vh;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
  padding-left: var(--safe-lr);
  padding-right: var(--safe-lr);
}

.top-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  background: linear-gradient(180deg,
    rgba(15, 21, 38, 0.95) 0%,
    rgba(15, 21, 38, 0.88) 100%);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 1px 0 rgba(225,176,71,0.08), 0 8px 20px rgba(0,0,0,0.35);
}

.header-logo {
  width: 26px; height: 26px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 4px rgba(225, 176, 71, 0.25));
}

.top-title {
  margin: 0;
  font-family: var(--brand-font);
  font-size: 14px;
  font-weight: 400;       /* Ethnocentric is a display face — don't bold it */
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  flex: 1;
  text-align: center;
  text-shadow: 0 1px 10px rgba(225, 176, 71, 0.25);
}

.top-right { margin-left: auto; }

.icon-btn {
  background: transparent;
  color: var(--gold);
  border: 0;
  font-size: 22px;
  line-height: 1;
  padding: 8px 12px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.icon-btn:active { background: rgba(225,176,71,0.14); }

/* Sync status pill */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge-ok   { color: var(--ok);    border-color: rgba(94,207,150,0.4); background: rgba(94,207,150,0.08); }
.badge-sync { color: var(--gold);  border-color: rgba(225,176,71,0.5); background: rgba(225,176,71,0.12);
              animation: pulse 1.4s ease-in-out infinite; }
.badge-warn { color: var(--warn);  border-color: rgba(232,185,71,0.5); background: rgba(232,185,71,0.10); }
.badge-danger{color: var(--danger);border-color: rgba(240,100,80,0.5); background: rgba(240,100,80,0.10); }

@keyframes pulse {
  0%,100% { opacity: 0.55; }
  50%     { opacity: 1.0; }
}

/* ==========================================================================
   View root
   ========================================================================== */
.view-root {
  flex: 1;
  padding: 20px 18px 40px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fadeUp 280ms ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Login
   ========================================================================== */
.view-login {
  min-height: calc(100vh - var(--safe-top) - var(--safe-bot) - 40px);
  justify-content: center;
  gap: 28px;
}

.login-brand {
  text-align: center;
  margin: 20px 0 12px;
}

.login-logo {
  display: block;
  width: 128px;
  height: auto;
  max-height: 128px;
  margin: 0 auto 18px;
  object-fit: contain;
  filter:
    drop-shadow(0 12px 32px rgba(225, 176, 71, 0.30))
    drop-shadow(0 2px 8px rgba(0, 0, 0, 0.50));
}

.login-name {
  font-family: var(--brand-font);
  font-size: 28px;
  font-weight: 400;          /* Ethnocentric display weight */
  letter-spacing: 0.22em;
  color: var(--text);
  margin-bottom: 8px;
}

.login-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.85;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.api-hint {
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--text-mute);
}
.api-hint label { letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; }
.api-hint input {
  padding: 8px 10px; font-size: 12px; min-width: 0;
  background: var(--bg-0); border: 1px solid var(--line);
  color: var(--text-dim); border-radius: var(--r-sm);
}

/* ==========================================================================
   Fields / Forms
   ========================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.field > legend {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
  padding: 0;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="url"],
.field textarea,
.field select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 13px 14px;
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-size: 16px;        /* 16px prevents iOS zoom on focus */
  line-height: 1.35;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) 50%,
    calc(100% - 15px) 50%;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow), inset 0 1px 0 rgba(255,255,255,0.04);
  background: var(--bg-2);
}

textarea { resize: vertical; min-height: 80px; }

fieldset.field {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 14px 16px;
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

fieldset.field > legend {
  padding: 0 8px;
  margin-left: 2px;
}

/* Time pickers */
.time-field .time-pickers {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: end;
  gap: 8px;
}
.time-unit {
  display: flex; flex-direction: column; gap: 4px;
}
.time-unit > span {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}
.time-unit input {
  text-align: center;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.04em;
  padding: 12px 6px;
}
.time-colon {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
  line-height: 48px;
  transform: translateY(-2px);
}
.time-hint {
  font-size: 12px;
  color: var(--text-mute);
  min-height: 1em;
  margin-top: 4px;
}
.time-hint.warn { color: var(--warn); }
.time-hint.err  { color: var(--danger); }

/* Parts list */
.parts-list { display: flex; flex-direction: column; gap: 8px; }

.part-row {
  display: grid;
  grid-template-columns: 1fr 72px auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
}
.part-row select { padding: 10px 12px; font-size: 14px; }
.part-row input { padding: 10px 10px; font-size: 14px; text-align: center; }
.part-row .part-remove {
  background: transparent;
  color: var(--danger);
  border: 0;
  font-size: 22px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--r-sm);
}
.part-row .part-remove:active { background: rgba(240,100,80,0.14); }

/* Media grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.media-grid:empty { display: none; }
.media-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.media-thumb img, .media-thumb video {
  width: 100%; height: 100%; object-fit: cover;
}
.media-thumb .media-remove {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px;
  border-radius: 12px;
  background: rgba(0,0,0,0.65);
  color: #fff; border: 0;
  font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.media-thumb .media-check {
  position: absolute; bottom: 4px; right: 4px;
  font-size: 11px;
  color: var(--ok);
  background: rgba(0,0,0,0.55);
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
}
.media-add-btn {
  text-align: center;
  justify-content: center;
  border-style: dashed !important;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  border-radius: var(--r);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 46px;       /* iOS tap target */
  transition: transform 120ms ease, box-shadow 140ms ease, background 140ms ease,
              border-color 140ms ease, color 140ms ease, opacity 140ms ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn[disabled], .btn:disabled {
  opacity: 0.45; cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(180deg, var(--gold-soft) 0%, var(--gold) 55%, var(--gold-deep) 100%);
  color: var(--text-on-gold);
  border-color: transparent;
  box-shadow:
    0 6px 16px rgba(225, 176, 71, 0.35),
    inset 0 -2px 0 rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.22);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.btn-primary:active {
  transform: translateY(1px);
  box-shadow:
    0 3px 8px rgba(225, 176, 71, 0.30),
    inset 0 -1px 0 rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.12);
}

.btn-ghost {
  background: var(--bg-2);
  color: var(--text);
  border-color: var(--line);
}
.btn-ghost:active {
  background: var(--bg-3);
  border-color: var(--gold);
  color: var(--gold);
}

.btn-danger {
  color: var(--danger) !important;
  border-color: rgba(240, 100, 80, 0.25) !important;
  background: rgba(240, 100, 80, 0.05) !important;
}

.btn-small {
  padding: 9px 12px;
  font-size: 13px;
  min-height: 36px;
}

.btn-large {
  padding: 18px 20px;
  font-size: 16px;
  min-height: 56px;
  border-radius: var(--r-lg);
}

/* Form error / hint */
.form-error {
  background: rgba(240, 100, 80, 0.1);
  border: 1px solid rgba(240, 100, 80, 0.3);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--r);
  font-size: 13px;
  margin: 0;
}

/* ==========================================================================
   Home
   ========================================================================== */
.view-home { gap: 14px; }

.hello {
  padding: 20px;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.hello-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 4px;
  font-weight: 600;
}
.hello-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.sync-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  margin-top: 4px;
}
.sync-meta > span {
  font-size: 12px;
  color: var(--text-mute);
  letter-spacing: 0.02em;
}

/* ==========================================================================
   Records list
   ========================================================================== */
.view-records { gap: 10px; }

.records-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.record-card {
  padding: 16px;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease;
}
.record-card:active {
  transform: translateY(1px);
  border-color: var(--gold);
}
.record-card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.record-card-title {
  font-size: 15px; font-weight: 700; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.record-card-status {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-dim); background: var(--bg-2);
  font-weight: 700; flex-shrink: 0;
}
.record-card-status.status-resolved,
.record-card-status.status-signed_off {
  color: var(--ok); border-color: rgba(94,207,150,0.4); background: rgba(94,207,150,0.08);
}
.record-card-status.status-on_site,
.record-card-status.status-diagnosing {
  color: var(--gold); border-color: rgba(225,176,71,0.5); background: rgba(225,176,71,0.12);
}
.record-card-meta {
  font-size: 12px; color: var(--text-mute);
  display: flex; gap: 8px; flex-wrap: wrap;
}
.record-card-meta > span::before {
  content: "·"; margin-right: 8px; color: var(--gold);
}
.record-card-meta > span:first-child::before { content: ""; margin: 0; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-mute);
  font-size: 14px;
}

/* Record detail */
.record-detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.record-detail-section {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
}
.record-detail-section h3 {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold); font-weight: 700;
  margin: 0 0 10px;
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-root {
  position: fixed;
  top: calc(var(--safe-top) + 60px);
  left: 0; right: 0;
  padding: 0 16px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  max-width: 520px;
  margin: 6px auto;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toastIn 200ms ease, toastOut 200ms ease 3.5s forwards;
  pointer-events: auto;
}
.toast.ok     { border-left: 3px solid var(--ok); }
.toast.err    { border-left: 3px solid var(--danger); }
.toast.info   { border-left: 3px solid var(--gold); }

@keyframes toastIn  { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-8px); } }

/* ==========================================================================
   Misc
   ========================================================================== */
hr {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
  margin: 10px 0;
}

::-webkit-scrollbar { width: 0; height: 0; }

/* Respect reduce-motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* Big screens (tablet / iPad) */
@media (min-width: 600px) {
  .view-root { padding: 28px 24px 60px; }
  .media-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---- Media modal (tap-to-enlarge photo/video viewer) ---- */
.media-modal {
  position: fixed; inset: 0;
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.media-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  cursor: pointer;
}
.media-modal-content {
  position: relative;
  max-width: min(100%, 1400px);
  max-height: 92vh;
  display: flex; align-items: center; justify-content: center;
}
.media-modal-content > * { max-width: 100%; max-height: 92vh; }
.media-modal-content img,
.media-modal-content video {
  display: block;
  max-width: 100%;
  max-height: 92vh;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.media-modal-close {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 2;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(20, 22, 30, 0.85);
  color: var(--text, #f4f0e7);
  font-size: 24px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.media-modal-close:hover { background: rgba(40, 42, 50, 0.95); }

/* Admin edit/delete row in record detail */
.admin-actions { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.admin-actions button { flex: 1 1 auto; min-width: 140px; }
