/* ================================================================
   УчётАвто — оформление в стиле iOS (Apple Human Interface)
   Светлая и тёмная темы переключаются автоматически по теме
   Телеграма (color-scheme на <html> задаёт app.js).
   ================================================================ */

:root {
  /* iOS-палитра, светлая тема */
  --bg: #f2f2f7;                       /* systemGroupedBackground */
  --card: #ffffff;
  --card-secondary: rgba(120, 120, 128, 0.12);
  --text: #000000;                     /* label */
  --hint: rgba(60, 60, 67, 0.6);       /* secondaryLabel */
  --separator: rgba(60, 60, 67, 0.14); /* hairline */
  --accent: #007aff;                   /* systemBlue */
  --green: #34c759;                    /* systemGreen */
  --red: #ff3b30;                      /* systemRed */
  --orange: #ff9500;                   /* systemOrange */
  --tabbar-bg: rgba(249, 249, 249, 0.94);
  --seg-active: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;                   /* secondarySystemGroupedBackground */
    --card-secondary: rgba(120, 120, 128, 0.24);
    --text: #ffffff;
    --hint: rgba(235, 235, 245, 0.6);
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --orange: #ff9f0a;
    --tabbar-bg: rgba(24, 24, 26, 0.92);
    --seg-active: #636366;
    --shadow: none;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 16px 16px 96px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.1px;
}

button, input, select { font-family: inherit; }

/* ------------------------------------------------------------- загрузка */
.loading { text-align: center; padding: 80px 0; color: var(--hint); }
.spinner {
  width: 32px; height: 32px; margin: 0 auto 14px;
  border: 3px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- шапка */
.header { display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 18px; }
.header h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.6px;
  line-height: 1.1; }
.header .sub { color: var(--hint); font-size: 13px; margin-top: 3px; }
.refresh {
  border: none; background: var(--card); color: var(--accent);
  font-size: 18px; width: 42px; height: 42px; border-radius: 21px;
  cursor: pointer; box-shadow: var(--shadow); flex-shrink: 0;
  transition: transform 0.1s;
}
.refresh:active { transform: scale(0.92); opacity: 0.7; }

/* ------------------------------------------------------------- карточки */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 15px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 20px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px 15px;
  box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--hint); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.stat .value { font-size: 20px; font-weight: 700; letter-spacing: -0.4px; }
.stat .value.green { color: var(--green); }
.stat .value.red { color: var(--red); }

.debt-banner {
  background: var(--card); border-radius: 16px; padding: 15px 16px;
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; box-shadow: var(--shadow);
}
.debt-banner .label { font-size: 13px; color: var(--hint); }
.debt-banner .value { font-size: 22px; font-weight: 800; color: var(--red);
  letter-spacing: -0.4px; }
.debt-banner .value.ok { color: var(--green); }

h2.section { font-size: 15px; font-weight: 600; color: var(--hint);
  margin: 22px 4px 10px; text-transform: none; letter-spacing: 0; }

/* -------------------------------------------------------------- списки */
.row-item {
  background: var(--card); border-radius: 16px; padding: 13px 16px;
  margin-bottom: 8px; display: flex; justify-content: space-between;
  align-items: center; gap: 10px; box-shadow: var(--shadow);
}
.row-item .title { font-weight: 600; font-size: 16px; letter-spacing: -0.2px; }
.row-item .subtitle { font-size: 12.5px; color: var(--hint); margin-top: 2px; }
.badge {
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  padding: 5px 11px; border-radius: 99px;
}
.badge.debt { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.badge.ok { background: rgba(52, 199, 89, 0.14); color: var(--green); }
.badge.free { background: var(--card-secondary); color: var(--hint); }
.badge.pending { background: rgba(255, 149, 0, 0.14); color: var(--orange); }

/* ------------------------------------------------------------ водитель */
.big-number { font-size: 34px; font-weight: 800; margin: 4px 0 2px;
  letter-spacing: -0.8px; }
.big-number.red { color: var(--red); }
.big-number.green { color: var(--green); }
.hint { font-size: 12.5px; color: var(--hint); }

.kv { display: flex; justify-content: space-between; padding: 11px 0;
  border-bottom: 0.5px solid var(--separator); font-size: 15px; gap: 12px; }
.kv:last-child { border-bottom: none; padding-bottom: 2px; }
.kv .k { color: var(--hint); }
.kv .v { font-weight: 600; text-align: right; }

.empty { color: var(--hint); text-align: center; padding: 30px 0;
  font-size: 14px; }

.access-denied { text-align: center; padding: 70px 20px; color: var(--hint); }
.access-denied .icon { font-size: 46px; margin-bottom: 14px; }

/* ------------------------------------------------------ нижнее меню */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex;
  background: var(--tabbar-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: 0.5px solid var(--separator);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1; border: none; background: none; color: var(--hint);
  font-size: 10.5px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; padding: 4px 0; cursor: pointer;
}
.tab .tab-icon { font-size: 21px; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- кнопки */
.btn {
  border: none; background: var(--card-secondary); color: var(--accent);
  font-size: 15px; font-weight: 600; padding: 12px 14px;
  border-radius: 13px; cursor: pointer; transition: transform 0.1s;
  letter-spacing: -0.1px;
}
.btn:active { transform: scale(0.97); opacity: 0.75; }
.btn:disabled { opacity: 0.4; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.btn.wide { display: block; width: 100%; margin-bottom: 10px; }
.btn.back { margin-bottom: 12px; padding: 8px 14px; font-size: 14px; }
.icon-btn {
  border: none; background: none; font-size: 17px; cursor: pointer;
  padding: 4px;
}
.row-item.clickable { cursor: pointer; }
.row-item.clickable:active { opacity: 0.6; }
.green { color: var(--green); }
.red { color: var(--red); }
.warn-card { background: rgba(255, 149, 0, 0.12); font-size: 13px;
  box-shadow: none; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn { text-align: center; }
.btn.small-ok { padding: 8px 12px; font-size: 13px;
  background: rgba(52, 199, 89, 0.14); color: var(--green); }

/* ------------------------------------------------------------------ график */
.chart { display: flex; gap: 7px; align-items: stretch; height: 150px; }
.chart-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chart-bars { flex: 1; display: flex; gap: 3px; align-items: flex-end; }
.bar { flex: 1; border-radius: 5px 5px 0 0; min-height: 3px; }
.bar.in { background: var(--green); }
.bar.out { background: var(--red); opacity: 0.8; }
.chart-label { text-align: center; font-size: 10.5px; color: var(--hint);
  margin-top: 5px; }
.chart-net { text-align: center; font-size: 10px; font-weight: 700;
  white-space: nowrap; }

.photo-view { width: 100%; border-radius: 14px; }

/* ------------------------------------------------------- сегменты/пагер */
.segment { display: flex; background: var(--card-secondary);
  border-radius: 10px; padding: 2px; margin-bottom: 12px; }
.seg { flex: 1; border: none; background: none; color: var(--text);
  font-size: 13.5px; font-weight: 600; padding: 8px 0; border-radius: 8px;
  cursor: pointer; transition: background 0.15s; }
.seg.active { background: var(--seg-active);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
.pager { display: flex; justify-content: center; align-items: center;
  gap: 14px; margin-top: 12px; color: var(--hint); font-size: 13px; }

/* ---------------------------------------------------------------- модалки */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadein 0.18s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: var(--bg); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; padding: 18px 16px
    calc(18px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; overflow-y: auto;
  animation: slideup 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
  position: relative;
}
.modal::before { /* «ручка» шторки, как в iOS */
  content: ""; position: absolute; top: 7px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 5px; border-radius: 3px;
  background: rgba(120, 120, 128, 0.35);
}
@keyframes slideup { from { transform: translateY(60px); opacity: 0.6; } }
.modal-head { display: flex; justify-content: space-between;
  align-items: center; margin: 10px 0 14px; }
.modal-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.modal-x { border: none; background: var(--card-secondary);
  color: var(--hint); width: 30px; height: 30px; border-radius: 50%;
  font-size: 13px; cursor: pointer; flex-shrink: 0; }
.modal-body { font-size: 15px; line-height: 1.5; margin-bottom: 14px; }
.modal-body b { word-break: break-all; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12.5px; color: var(--hint);
  margin-bottom: 5px; }
.field input, .field select {
  width: 100%; font-size: 16px; padding: 12px 14px;
  border: none; border-radius: 13px;
  background: var(--card); color: var(--text);
  box-shadow: var(--shadow);
}
.field input:focus, .field select:focus {
  outline: none; box-shadow: 0 0 0 2.5px var(--accent);
}
.file-prev { display: none; max-width: 100%; max-height: 160px;
  border-radius: 14px; margin-top: 8px; }
.modal-submit { margin-top: 6px; }

/* ------------------------------------------------------------------ тост */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%)
    translateY(12px); z-index: 200; background: rgba(28, 28, 30, 0.95);
  color: #fff; font-size: 14px; font-weight: 600; padding: 11px 20px;
  border-radius: 99px; opacity: 0; transition: all 0.25s;
  max-width: 86vw; text-align: center;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
