/* ============================================================
   PetroOps Mini App — дизайн-система
   Адаптируется к теме Telegram (light/dark), с фолбэками.
   ============================================================ */

:root {
  /* Палитра бренда (нефтегаз: глубокий индиго + янтарь) */
  --brand: #2f6df6;
  --brand-600: #1f5be0;
  --brand-700: #1648be;
  --brand-soft: rgba(47, 109, 246, 0.12);
  --accent: #f5a623;
  --accent-soft: rgba(245, 166, 35, 0.14);
  --success: #2ecc71;
  --danger: #e5484d;

  /* Тема Telegram с фолбэками (светлая) */
  --bg: var(--tg-theme-bg-color, #f5f7fb);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-2: var(--tg-theme-secondary-bg-color, #eef1f7);
  --text: var(--tg-theme-text-color, #11161f);
  --hint: var(--tg-theme-hint-color, #8b94a3);
  --link: var(--tg-theme-link-color, var(--brand));
  --button: var(--tg-theme-button-color, var(--brand));
  --button-text: var(--tg-theme-button-text-color, #ffffff);

  --border: color-mix(in srgb, var(--text) 12%, transparent);
  --border-soft: color-mix(in srgb, var(--text) 7%, transparent);
  --shadow-sm: 0 1px 2px rgba(16, 22, 31, 0.06), 0 1px 3px rgba(16, 22, 31, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 22, 31, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 22, 31, 0.14);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --gap: 12px;

  --header-h: 56px;
  --tabbar-h: 64px;
}

/* Если Telegram сообщает тёмную тему — усиливаем контраст подложки. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #0f1420);
    --surface: var(--tg-theme-bg-color, #171d2b);
    --surface-2: var(--tg-theme-secondary-bg-color, #0b0f18);
    --text: var(--tg-theme-text-color, #eef2f8);
    --hint: var(--tg-theme-hint-color, #8b94a3);
    --border: color-mix(in srgb, #ffffff 12%, transparent);
    --border-soft: color-mix(in srgb, #ffffff 7%, transparent);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Атрибут hidden должен побеждать любые display из правил ниже. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}
.inline-icon {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  color: currentColor;
}
.btn-icon {
  width: 18px;
  height: 18px;
}
.badge-icon,
.link-icon {
  width: 14px;
  height: 14px;
}
.empty-icon {
  width: 42px;
  height: 42px;
}
.lead-svg {
  width: 22px;
  height: 22px;
}

/* ───────────── Шапка ───────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--header-h);
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.back-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--surface-2); border: none; color: var(--link);
  font-size: 15px; font-weight: 600; cursor: pointer;
  padding: 7px 12px; border-radius: 999px;
  transition: transform .12s ease, opacity .12s ease;
}
.back-btn:active { transform: scale(0.94); opacity: .8; }
.topbar .title {
  font-weight: 700; font-size: 18px; letter-spacing: -0.2px;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .brand-dot {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; box-shadow: var(--shadow-sm);
}

/* ───────────── Контент ───────────── */
main {
  padding: 16px;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 680px; margin: 0 auto;
  animation: viewIn .26s ease;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.loader { text-align: center; color: var(--hint); padding: 48px 0; }

/* Скелетоны загрузки */
.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface-2) 30%, color-mix(in srgb, var(--surface-2) 60%, var(--surface)) 50%, var(--surface-2) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  margin-bottom: 10px;
}
.skeleton.line { height: 14px; }
.skeleton.row { height: 64px; }
.skeleton.block { height: 120px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ───────────── Карточки ───────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.card .row { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--border-soft); }
.card .row:last-child { border-bottom: none; }
.card .row .k { color: var(--hint); min-width: 104px; font-size: 13px; font-weight: 500; }
.card .row .v { font-weight: 600; flex: 1; }
.card .name { font-weight: 700; font-size: 17px; }
.card .sub { color: var(--hint); font-size: 13px; }

/* Профиль: «герой» с аватаром */
.profile-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 16px; margin-bottom: 14px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--brand-soft), transparent 60%),
    var(--surface);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-md);
}
.avatar {
  width: 58px; height: 58px; flex: 0 0 auto; border-radius: 18px;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  box-shadow: var(--shadow-sm);
}
.profile-hero .who { min-width: 0; }
.profile-hero .who .nm { font-size: 19px; font-weight: 800; letter-spacing: -0.3px; }
.profile-hero .who .pos { color: var(--hint); font-size: 14px; margin-top: 2px; }

/* Бейдж роли */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  margin-top: 6px;
}
.badge.admin { background: var(--accent-soft); color: #b9770a; }
.badge.user { background: var(--brand-soft); color: var(--brand-700); }
@media (prefers-color-scheme: dark) {
  .badge.admin { color: var(--accent); }
  .badge.user { color: #8fb3ff; }
}

/* ───────────── Списки ───────────── */
.list-item {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.list-item[role="button"] { cursor: pointer; }
.list-item[role="button"]:active { transform: scale(0.985); background: var(--surface-2); }
.list-item .lead {
  width: 42px; height: 42px; flex: 0 0 auto; border-radius: 12px;
  display: grid; place-items: center; font-size: 18px; font-weight: 700;
  background: var(--surface-2); color: var(--text);
}
.list-item .lead.tint { background: var(--brand-soft); color: var(--brand-700); }
@media (prefers-color-scheme: dark) { .list-item .lead.tint { color: #8fb3ff; } }
.list-item .meta { min-width: 0; flex: 1; }
.list-item .meta .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta .sub { color: var(--hint); font-size: 13px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .trail { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.chevron { color: var(--hint); font-size: 22px; line-height: 1; opacity: .6; }

/* ───────────── Кнопки ───────────── */
button.btn {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--button); color: var(--button-text);
  border: none; border-radius: 14px;
  padding: 14px 16px; font-size: 16px; font-weight: 700;
  width: 100%; cursor: pointer; margin-top: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, filter .12s ease;
}
button.btn:active { transform: scale(0.985); filter: brightness(0.96); }
button.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
button.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none; }
button.btn.small { width: auto; padding: 9px 14px; font-size: 14px; margin: 0; }

.btn-link {
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  width: 100%; margin-top: 10px; padding: 14px 16px;
  border-radius: 14px; background: var(--button); color: var(--button-text);
  text-decoration: none; font-size: 16px; font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.action-grid .btn { margin-top: 0; }

.search-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

/* ───────────── Плитки ───────────── */
.tile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 22px 14px; text-align: center;
  font-weight: 700; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:active { transform: translateY(1px) scale(0.99); box-shadow: var(--shadow-md); }
.tile-icon {
  display: grid; place-items: center;
  width: 52px; height: 52px; margin: 0 auto 10px; border-radius: 16px;
  background: var(--brand-soft);
  color: var(--brand-700);
}
.tile-icon .icon {
  width: 26px;
  height: 26px;
}
.tile-sub {
  margin-top: 6px;
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
}
.request-grid .tile {
  padding: 18px 10px;
  min-height: 142px;
}

/* ───────────── Формы ───────────── */
label.field { display: block; margin: 14px 0 6px; color: var(--hint); font-size: 13px; font-weight: 600; }
label.field.compact { margin-top: 0; }
input.inp, textarea.inp, select.inp {
  width: 100%; padding: 13px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 13px;
  background: var(--surface); color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input.inp:focus, textarea.inp:focus, select.inp:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea.inp { min-height: 130px; resize: vertical; line-height: 1.5; }
input[type="file"].inp { padding: 11px 14px; }

/* Сегментированный контрол */
.segment {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: 14px; margin-bottom: 14px;
}
.segment button {
  flex: 1; border: none; background: transparent; color: var(--hint);
  font-size: 14px; font-weight: 600; padding: 9px 8px; border-radius: 11px;
  cursor: pointer; transition: all .15s ease;
}
.segment button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.request-scope,
.request-filter {
  margin-bottom: 12px;
}
.request-filter button {
  font-size: 13px;
  padding-inline: 5px;
}

/* ───────────── Очередь заявок ───────────── */
.request-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.request-stats div {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 11px 10px;
  box-shadow: var(--shadow-sm);
}
.request-stats span {
  display: block;
  font-size: 20px;
  font-weight: 800;
}
.request-stats small {
  display: block;
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
}
.request-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.request-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.request-head .lead {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand-700);
}
.request-head .meta {
  min-width: 0;
  flex: 1;
}
.request-head .name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.request-head .sub {
  color: var(--hint);
  font-size: 13px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 132px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status-badge.new { background: var(--accent-soft); color: #a96500; }
.status-badge.progress { background: var(--brand-soft); color: var(--brand-700); }
.status-badge.done { background: color-mix(in srgb, var(--success) 15%, transparent); color: #187a42; }
.status-badge.rejected { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.status-badge.neutral { background: var(--surface-2); color: var(--hint); }
.request-path,
.request-money,
.request-decision {
  margin-top: 10px;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
}
.request-text {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 14px;
  white-space: pre-wrap;
}
.request-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.request-actions .btn {
  width: 100%;
  margin-top: 0;
}
@media (prefers-color-scheme: dark) {
  .status-badge.new { color: var(--accent); }
  .status-badge.progress { color: #8fb3ff; }
  .status-badge.done { color: #7ee2a4; }
}

/* ───────────── Таб-бар ───────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--border-soft);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  flex: 1 0 66px; background: none; border: none; cursor: pointer;
  color: var(--hint); font-size: 10.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 3px 0; transition: color .15s ease;
}
.tabbar button span.ico {
  display: grid; place-items: center; width: 40px; height: 28px;
  border-radius: 12px; transition: background .18s ease, transform .15s ease;
}
.tabbar button span.ico .icon {
  width: 21px;
  height: 21px;
}
.tabbar button.active { color: var(--brand); }
.tabbar button.active span.ico { background: var(--brand-soft); transform: translateY(-1px); }

/* ───────────── Прочее ───────────── */
.empty {
  text-align: center; color: var(--hint); padding: 56px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty .big { opacity: .7; color: var(--hint); }
.section-title { font-weight: 700; font-size: 14px; color: var(--hint); text-transform: uppercase; letter-spacing: .4px; margin: 2px 2px 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 28px); transform: translateX(-50%) translateY(8px);
  background: color-mix(in srgb, var(--text) 90%, transparent); color: var(--bg);
  padding: 11px 18px; border-radius: 13px; font-size: 14px; font-weight: 600;
  z-index: 60; max-width: 90%; box-shadow: var(--shadow-lg);
  opacity: 0; animation: toastIn .22s ease forwards;
}
@keyframes toastIn { to { opacity: 1; transform: translateX(-50%) translateY(0); } }

a.link {
  color: var(--link); text-decoration: none; font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 10px; border-radius: 999px; background: var(--brand-soft);
  white-space: nowrap;
}
a.link:active { filter: brightness(0.95); }
a.link.idcard { background: var(--accent-soft); color: #b9770a; }
@media (prefers-color-scheme: dark) { a.link.idcard { color: var(--accent); } }

.doc-preview {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-soft); box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
.doc-preview .ficon {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 12px;
  display: grid; place-items: center; color: #b9770a;
  background: var(--accent-soft);
}
.doc-preview .ficon .icon {
  width: 24px;
  height: 24px;
}
