/* L-Keeper · Mini App. Токены и вид — docs/DESIGN.md, эталон вёрстки — design/prototype.html */
:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #E9EEF4;
  --panel: #D5DEE9;
  --line: #B7C4D4;
  --card: #fff;
  --text: #14202E;
  --muted: #4B5D75;
  --grey: #4B6079;
  --tile: #2F6FB5;
  --green: #2E7D32;
  --orange: #BF4A00;
  --red: #B3261E;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E2A38;
    --panel: #2B3A4D;
    --line: #3C4D63;
    --card: #16202B;
    --text: #fff;
    --muted: #C9D3DF;
    --grey: #3C4D63;
  }
}

:root[data-theme="dark"] {
  --bg: #1E2A38;
  --panel: #2B3A4D;
  --line: #3C4D63;
  --card: #16202B;
  --text: #fff;
  --muted: #C9D3DF;
  --grey: #3C4D63;
}

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font: inherit;
  font-weight: 700;
  color: #fff;
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 14px;
  cursor: pointer;
  background: var(--grey);
  touch-action: manipulation;
}

button small { display: block; font-size: 11px; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }

:focus-visible { outline: 3px solid #FFB74D; outline-offset: 2px; }

.g { background: var(--green); }
.r { background: var(--red); }
.o { background: var(--orange); }
.t { background: var(--tile); }
.n { background: var(--grey); }
.sm { min-height: 44px; padding: 0 12px; }

.top {
  background: var(--panel);
  min-height: 56px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 2px solid var(--line);
  flex: none;
}

.top .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar {
  background: var(--panel);
  padding: 10px;
  display: flex;
  gap: 8px;
  border-top: 2px solid var(--line);
  flex: none;
}

.bar button { flex: 1; min-height: 52px; padding: 0 8px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.grid.three { grid-template-columns: repeat(3, 1fr); }

.tile {
  min-height: 92px;
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--tile);
}

.tl {
  min-height: 72px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  line-height: 1.25;
  background: var(--green);
}

.stat {
  border-radius: 8px;
  padding: 12px;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  background: var(--grey);
}

.stat.g { background: var(--green); }

.card { background: var(--card); border-radius: 8px; padding: 4px 12px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}

.row:last-child { border-bottom: 0; }
.row.wrap { flex-wrap: wrap; }
.row.grow > .grow { flex: 1; min-width: 38%; }
.user-row {
  width: 100%;
  background: transparent;
  color: var(--text);
  font-weight: 400;
  padding: 0;
  border-radius: 0;
  text-align: left;
}

.tot { font-size: 20px; font-weight: 700; }
.mut { color: var(--muted); font-size: 13px; }
.lbl { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: none;
  padding-bottom: 4px;
}

.tabs button { white-space: nowrap; flex: none; min-height: 44px; }

.rec { max-height: 32%; overflow: auto; flex: none; }

.qtybox { display: flex; align-items: center; gap: 6px; }
.qbtn { min-width: 44px; padding: 0; }
.qval { min-width: 24px; text-align: center; }
.sum { min-width: 64px; text-align: right; }

.drop {
  position: absolute;
  top: 56px;
  right: 10px;
  z-index: 5;
  width: 230px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

.drop button { text-align: left; }

.ov {
  position: absolute;
  inset: 0;
  z-index: 9;
  background: rgba(10, 16, 24, .78);
  display: flex;
  align-items: center;
  padding: 24px;
}

.dlg {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dlg .actions { display: flex; gap: 8px; }
.dlg .actions button { flex: 1; }
.dlg .close-x { align-self: flex-end; flex: none; min-width: 44px; padding: 0; }
.dlg .pick { text-align: left; }

input, select {
  min-height: 52px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: 18px Inter, system-ui, sans-serif;
  padding: 0 14px;
  width: 100%;
  box-sizing: border-box;
}

.mark-row { border-radius: 6px; }
.mark-row.on { background: var(--green); color: #fff; margin: 0 -12px; padding: 0 12px; }
.mark-row .pick {
  flex: 1;
  text-align: left;
  background: transparent;
  color: inherit;
  padding: 0;
  min-height: 52px;
}
.mark-row .pick small { font-weight: 400; font-size: 13px; }

.receipt {
  background: #fff;
  color: #111;
  width: 300px;
  max-width: 100%;
  box-sizing: border-box;
  padding: 18px 16px;
  font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
  align-self: center;
}

.receipt hr { border: 0; border-top: 1px dashed #111; margin: 10px 0; }
.receipt .brand { text-align: center; }
.receipt .brand b { font-size: 20px; letter-spacing: 2px; }
.receipt .line { display: flex; justify-content: space-between; gap: 8px; }
.receipt .foot { text-align: center; font-size: 11px; }

.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 90px;
  max-width: 90%;
  background: #111;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  z-index: 20;
  text-align: center;
}
