/* Arvekaamera – kujundus Apple Human Interface Guidelines'i põhimõtetel:
   süsteemne kirjatüüp, grupeeritud kaardid hallil taustal, üks rõhuvärv (tint),
   vähemalt 44px puutealad, poolläbipaistvad ribad, hele/tume režiim. */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;               /* systemGroupedBackground */
  --card: #ffffff;             /* secondarySystemGroupedBackground */
  --ink: #1c1c1e;              /* label */
  --muted: rgba(60, 60, 67, .62);   /* secondaryLabel */
  --faint: rgba(60, 60, 67, .32);   /* tertiaryLabel */
  --line: rgba(60, 60, 67, .18);    /* separator */
  --fill: rgba(118, 118, 128, .12); /* tertiarySystemFill */
  --fill-2: rgba(118, 118, 128, .2);
  --bar: rgba(249, 249, 249, .82);  /* navigatsiooniriba materjal */
  --tint: #0c7a79;             /* Cinecrafti türkiis, kontrastne */
  --tint-soft: rgba(12, 122, 121, .12);
  --on-tint: #ffffff;
  --ok: #248a3d; --ok-soft: rgba(52, 199, 89, .15);
  --warn: #c93400; --warn-soft: rgba(255, 149, 0, .16);
  --err: #d70015; --err-soft: rgba(255, 59, 48, .13);
  --info: #0040dd; --info-soft: rgba(0, 122, 255, .12);
  --radius: 12px; --radius-s: 10px;
  --tabbar-h: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --card: #1c1c1e; --ink: #f2f2f7;
    --muted: rgba(235, 235, 245, .6); --faint: rgba(235, 235, 245, .3);
    --line: rgba(84, 84, 88, .6); --fill: rgba(118, 118, 128, .24); --fill-2: rgba(118, 118, 128, .32);
    --bar: rgba(28, 28, 30, .78);
    --tint: #3cc6c3; --tint-soft: rgba(60, 198, 195, .18); --on-tint: #00201f;
    --ok: #30d158; --ok-soft: rgba(48, 209, 88, .18);
    --warn: #ff9f0a; --warn-soft: rgba(255, 159, 10, .18);
    --err: #ff453a; --err-soft: rgba(255, 69, 58, .18);
    --info: #409cff; --info-soft: rgba(10, 132, 255, .2);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
a { color: var(--tint); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.i { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Navigatsiooniriba */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--bar); color: var(--ink);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line); }
.brand { display: flex; gap: 8px; align-items: center; color: var(--ink); font-weight: 600; font-size: 17px; letter-spacing: -.2px; }
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
nav { display: flex; gap: 2px; }
/* Aktiivne firma päises */
.company { flex: 1; min-width: 0; font-size: 15px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company select { width: auto; max-width: 260px; min-height: 32px; padding: 4px 30px 4px 12px; font-size: 15px; font-weight: 600; color: var(--ink); border-radius: 99px; background-position: right 10px center; }
nav a { color: var(--muted); font-size: 15px; font-weight: 500; padding: 8px 12px; border-radius: 99px; }
nav a:hover { text-decoration: none; color: var(--ink); background: var(--fill); }
nav a.active { color: var(--tint); background: var(--tint-soft); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 120px; }
.center { text-align: center; } .muted { color: var(--muted); } .small { font-size: 13px; }

/* Grupeeritud kaardid */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
h1 { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.4px; margin: 4px 0 16px; }
h2 { font-size: 20px; font-weight: 600; letter-spacing: -.2px; margin: 0 0 12px; }

/* Nupud */
button, .btn { font: inherit; font-size: 17px; font-weight: 500; border: 0; border-radius: var(--radius-s);
  min-height: 44px; padding: 10px 18px; cursor: pointer; background: var(--fill); color: var(--tint);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity .15s, transform .1s, background-color .15s; }
button:hover, .btn:hover { text-decoration: none; background: var(--fill-2); }
button:active, .btn:active { transform: scale(.98); opacity: .8; }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--tint-soft); outline-offset: 2px; }
button.primary, .btn.primary, button.accent { background: var(--tint); color: var(--on-tint); font-weight: 600; }
button.primary:hover, .btn.primary:hover, button.accent:hover { background: var(--tint); opacity: .9; }
button.danger { background: var(--err-soft); color: var(--err); }
button.danger:hover { background: var(--err-soft); opacity: .85; }
button:disabled { opacity: .4; cursor: default; transform: none; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Pildistamine */
.capture { display: flex; flex-wrap: wrap; gap: 10px; }
.capture button { flex: 1 1 0; min-width: 0; padding: 14px 10px; font-size: 17px; }
.capture .big { flex-basis: 100%; min-height: 56px; font-size: 19px; border-radius: 14px; }
.capture .big svg.i { width: 1.3em; height: 1.3em; }
.inbox-hint { font-size: 13px; color: var(--muted); margin-top: 10px; line-height: 1.4; }
.inbox-hint:first-of-type { margin-top: 14px; }
.inbox-hint code { font: 500 13px ui-monospace, "SF Mono", Menlo, monospace; background: var(--fill); padding: 2px 6px; border-radius: 6px; color: var(--ink); }

/* Loendid (inset grouped) */
.list { list-style: none; padding: 0; margin: 0; }
.card > .list { margin: -16px; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 60px; cursor: pointer; position: relative; transition: background-color .12s; }
.list li + li::before { content: ""; position: absolute; top: 0; right: 0; left: 72px; border-top: .5px solid var(--line); }
.list li:hover { background: var(--fill); }
.list li:active { background: var(--fill-2); }
.list li:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.list li:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.list .thumb { width: 44px; height: 52px; border-radius: 8px; background: var(--fill) center/cover no-repeat; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .3px; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { font-size: 14px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sum { font-weight: 600; font-size: 17px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.list li[style*="cursor: default"]:hover, .list.users li:hover { background: transparent; }

/* Olekumärgid */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; vertical-align: 1px; margin-right: 4px; }
.badge.processing { background: var(--info-soft); color: var(--info); }
.badge.review { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--err-soft); color: var(--err); }
.badge.sent { background: var(--ok-soft); color: var(--ok); }

/* Segmenteeritud juhik */
.tabs { display: inline-flex; gap: 2px; padding: 2px; margin-bottom: 14px; background: var(--fill); border-radius: 9px; flex-wrap: wrap; max-width: 100%; }
.tabs button { min-height: 32px; padding: 6px 14px; font-size: 14px; font-weight: 500; color: var(--ink); background: transparent; border-radius: 7px; }
.tabs button:hover { background: transparent; opacity: .75; }
.tabs button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 1px 1px rgba(0,0,0,.04); }
@media (prefers-color-scheme: dark) { .tabs button.on { background: #636366; } }

/* Kontrollvaade */
.review-layout { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .review-layout { grid-template-columns: 1fr 1fr; align-items: start; } .preview { position: sticky; top: 72px; } }
.preview { background: #1c1c1e; border-radius: var(--radius); overflow: hidden; min-height: 200px; }
.preview img { width: 100%; display: block; max-height: 45vh; object-fit: contain; }
.preview iframe { width: 100%; height: 45vh; border: 0; background: #fff; }
@media (min-width: 900px) { .preview img { max-height: none; } .preview iframe { height: 75vh; } }

/* Vormid */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin: 0 0 5px 2px; }
input, select, textarea { width: 100%; font: inherit; font-size: 17px; min-height: 44px; padding: 10px 12px; border: 0; border-radius: var(--radius-s);
  background: var(--fill); color: var(--ink); -webkit-appearance: none; appearance: none; transition: box-shadow .15s, background-color .15s; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--tint); -webkit-appearance: auto; appearance: auto; vertical-align: middle; }
textarea { min-height: 88px; resize: vertical; }
select { padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 12px 8px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; background-color: var(--card); box-shadow: 0 0 0 2px var(--tint) inset; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input[type=search] { padding-left: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='5' fill='none' stroke='%238e8e93' stroke-width='1.8'/%3E%3Cpath d='M11 11l3.5 3.5' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; background-size: 16px; }
.changed { background-color: var(--warn-soft) !important; }

table.vat { width: 100%; border-collapse: collapse; }
table.vat th { font-size: 13px; color: var(--muted); text-align: left; font-weight: 500; padding: 4px; }
table.vat td { padding: 3px; } table.vat td:last-child { width: 44px; }
table.vat td button { min-height: 44px; padding: 8px; }
.totals { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 2px 0; margin-top: 10px; border-top: .5px solid var(--line); font-variant-numeric: tabular-nums; color: var(--muted); }
.totals b { font-size: 22px; color: var(--ink); font-weight: 700; letter-spacing: -.3px; }

/* Teated */
.alert { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 15px; line-height: 1.4; }
.alert.warn { background: var(--warn-soft); color: var(--ink); } .alert.warn b { color: var(--warn); }
.alert.err { background: var(--err-soft); color: var(--ink); } .alert.err b { color: var(--err); }
.alert.ok { background: var(--ok-soft); color: var(--ink); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* Alumine tegevusriba */
.sticky-actions { position: sticky; bottom: var(--tabbar-h); z-index: 5; margin: 0 -16px; padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line); }
.sticky-actions .primary { flex: 1; min-height: 50px; font-size: 17px; border-radius: 12px; }

#toast { position: fixed; left: 50%; bottom: calc(28px + var(--tabbar-h) + env(safe-area-inset-bottom)); transform: translate(-50%, 8px);
  background: rgba(28, 28, 30, .92); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px; font-weight: 500;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); box-shadow: 0 8px 30px rgba(0,0,0,.2);
  opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; max-width: 90vw; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.cat-row { display: grid; grid-template-columns: 1fr 110px 44px; gap: 8px; margin-bottom: 8px; align-items: center; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.login { max-width: 380px; margin: 12vh auto; }
.login h1 { text-align: center; }
[hidden] { display: none !important; }

.list.users li { flex-wrap: wrap; cursor: default; }
.list.users .actions { width: 100%; gap: 8px; padding-left: 0; }
.list.users .actions button { min-height: 36px; padding: 6px 14px; font-size: 15px; }

.filters { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.filters select, .filters input { font-size: 15px; min-height: 40px; padding-top: 8px; padding-bottom: 8px; }

/* Mobiil: navigatsioon allservas nagu iOS-i vahekaardiriba */
@media (max-width: 640px) {
  :root { --tabbar-h: calc(56px + env(safe-area-inset-bottom)); }
  html, body { font-size: 17px; }
  main { padding: 12px 16px calc(120px + var(--tabbar-h)); }
  h1 { font-size: 30px; }
  /* backdrop-filter teeks fikseeritud nav-i päise sisse lõksu – mobiilis on päis ilma hägustuseta */
  .company { flex: 0 1 auto; text-align: center; font-size: 13px; }
  .company select { max-width: 60vw; font-size: 14px; }
  .topbar { justify-content: center; flex-direction: column; gap: 2px; min-height: 44px; -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--bg); border-bottom-color: transparent; }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: var(--tabbar-h);
    padding: 4px 8px env(safe-area-inset-bottom); gap: 0;
    background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-top: .5px solid var(--line); }
  nav a { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; border-radius: 10px;
    font-size: 13px; font-weight: 500; padding: 0 4px; height: 48px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  nav a:hover { background: transparent; }
  nav a.active { background: transparent; color: var(--tint); font-weight: 600; }

  /* Vahekaardiriba ikoonid */
  nav a { flex-direction: column; gap: 2px; font-size: 11px; height: 50px; }
  nav a::before { content: ""; width: 26px; height: 26px; background: currentColor; -webkit-mask: var(--ic) center/contain no-repeat; mask: var(--ic) center/contain no-repeat; }
  nav a[href="#/"] { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 3h7l5 5v12a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z'/%3E%3Cpath d='M14 3v5h5M9 13h6M9 17h6'/%3E%3C/svg%3E"); }
  nav a[href="#/kasutajad"] { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.2'/%3E%3Cpath d='M3.5 19c.6-3.2 2.8-5 5.5-5s4.9 1.8 5.5 5'/%3E%3Ccircle cx='17' cy='9' r='2.5'/%3E%3Cpath d='M16 14.2c2.3.2 3.9 1.8 4.5 4.8'/%3E%3C/svg%3E"); }
  nav a[href="#/seaded"] { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z'/%3E%3C/svg%3E"); }
  nav a[href="#/konto"] { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3Cpath d='M6.2 18.4c1.2-2 3.3-3.2 5.8-3.2s4.6 1.2 5.8 3.2'/%3E%3C/svg%3E"); }
  .filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filters input { grid-column: 1 / -1; }
  .grid { grid-template-columns: 1fr; }
  .capture button { font-size: 16px; }
  .card { padding: 14px; }
  .card > .list { margin: -14px; }
}
