:root {
  --bg-grad-start: #070b1a;
  --bg-grad-end: #1c3a66;
  --bg: #0f1526;
  --surface: #161d34;
  --surface-2: #1e2743;
  --border: #2a3457;
  --border-2: #232c4a;
  --text: #e8ecf7;
  --text-muted: #8992b3;
  --text-soft: #aab2d1;
  --primary: #5b9bff;
  --primary-hover: #78acff;
  --primary-soft: #1c2c52;
  --primary-border: #2f4a86;
  --danger: #ff6b5a;
  --danger-soft: #3a1e1b;
  --success: #4ade80;
  --success-soft: #14321f;
  --warn: #f0a04b;
  --warn-soft: #3a2a17;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html {
  height: 100%;
  /* Заливка на случай резинового оверскролла на iOS — без этого видна белая
     полоса выше/ниже документа, потому что там просвечивает фон <html>. */
  background: var(--bg-grad-end);
}
body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  /* background-attachment: fixed мигает белым при резиновом оверскролле в iOS Safari — не используем */
  background: linear-gradient(160deg, var(--bg-grad-start) 0%, var(--bg-grad-end) 100%);
  background-repeat: no-repeat;
  color: var(--text);
  margin: 0;
}

/* ---------- topbar ---------- */
:root { --topbar-h: 62px; }
.topbar {
  background: linear-gradient(120deg, #101a36 0%, #1b2f57 100%);
  border-bottom: 1px solid var(--border);
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  height: var(--topbar-h);
  padding: 0 20px;
  display: flex; align-items: center; gap: 20px;
}
.brand {
  background: transparent; border: none; cursor: pointer;
  color: var(--text);
  width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand svg, .brand img { width: 24px; height: 24px; object-fit: contain; }
.brand:hover { background: var(--surface-2); }
.nav { display: flex; gap: 4px; margin-left: 12px; flex: 1; }
.nav-btn {
  background: transparent; border: none; color: var(--text-soft);
  font-size: 14px; font-weight: 600; padding: 8px 14px;
  border-radius: 8px; cursor: pointer; transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-soft);
  height: 38px; border-radius: 10px; cursor: pointer;
  font-size: 13px; font-weight: 600; line-height: 1;
  padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.icon-btn:hover { background: var(--border-2); color: var(--text); }

/* ---------- общее ---------- */
.container {
  max-width: 1200px; margin: 0 auto;
  padding: 24px 20px 60px;
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 24px);
}
h1 { font-size: 22px; margin: 0 0 20px; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 12px; color: var(--text-soft); }

.hidden { display: none !important; }

.card {
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 130%);
  padding: 18px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

/* ---------- формы ---------- */
.form-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.form-row label {
  display: flex; flex-direction: column;
  font-size: 13px; color: var(--text-muted); gap: 6px;
}
input, select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
input:disabled, select:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}
.form-row input, .form-row select { min-width: 200px; }

select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23aab2d1' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
table select { padding-right: 30px; background-position: right 8px center; }

/* Убираем стрелки увеличения/уменьшения у числовых полей — не нужны */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------- кнопки ---------- */
.btn {
  padding: 9px 16px; border-radius: 8px; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
  font-family: inherit;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, #3a6ae0 100%); color: #fff; }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-hover) 0%, #4a7af0 100%); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-2); }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-del {
  background: transparent; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 16px; padding: 4px 8px; border-radius: 6px;
}
.btn-del:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- шапка смены ---------- */
.shift-header {
  display: flex; gap: 24px; align-items: center; flex-wrap: wrap;
}
.shift-field { display: flex; flex-direction: column; gap: 4px; }
.shift-field .label {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.shift-field .value { font-weight: 600; font-size: 15px; }
.value-input {
  padding: 7px 10px; border: 1px solid transparent; border-radius: 8px;
  font-size: 15px; font-weight: 600; background: var(--surface-2);
  color: var(--text); min-width: 160px;
}
.value-input.small { min-width: 80px; max-width: 110px; }
.value-input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.value-input:disabled { background: transparent; padding-left: 0; }
.shift-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.closed-mark {
  color: var(--danger); font-weight: 600;
  background: var(--danger-soft); padding: 6px 12px;
  border-radius: 8px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}

/* ---------- таблица ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
.table-scroll table { min-width: 640px; }
th {
  text-align: left; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600;
  padding: 8px 6px; border-bottom: 1px solid var(--border);
}
td {
  padding: 6px 6px; border-bottom: 1px solid var(--border-2);
  vertical-align: middle;
}
table input[type="text"], table input[type="number"], table select {
  width: 100%; padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px; font-size: 14px;
  background: var(--surface); color: var(--text);
}
table input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer;
  accent-color: var(--primary);
}

/* ---------- итоги ---------- */
.totals {
  margin-top: 20px; border-top: 2px solid var(--border);
  padding-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.total-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 12px 14px;
  background: var(--surface-2); border-radius: 9px; font-size: 14px;
}
.total-row b { font-size: 16px; }
.total-row.highlight { background: var(--primary-soft); border: 1px solid var(--primary-border); }
.total-row.highlight b { color: var(--primary); }

/* ---------- дашборд ---------- */
.dash-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dash-filters .btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-soft); }
.dash-filters .btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.dash-custom {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}
.dash-custom input[type="date"] { padding: 7px 10px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px;
}
.kpi .kpi-label {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: 6px;
}
.kpi .kpi-value { font-size: 22px; font-weight: 700; }
.kpi .kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi.kpi-primary { background: var(--primary-soft); border-color: var(--primary-border); }
.kpi.kpi-primary .kpi-value { color: var(--primary); }
.kpi.kpi-success { background: var(--success-soft); }
.kpi.kpi-success .kpi-value { color: var(--success); }
.kpi.kpi-warn { background: var(--warn-soft); }
.kpi.kpi-warn .kpi-value { color: var(--warn); }

.split-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
@media (max-width: 800px) { .split-grid { grid-template-columns: 1fr; } }

.bar-chart-wrap { display: flex; gap: 10px; }
.bar-axis {
  display: flex; flex-direction: column; justify-content: space-between;
  height: 130px; padding-top: 10px;
  font-size: 11px; color: var(--text-muted); text-align: right;
  flex: 0 0 auto;
}
.bar-chart {
  display: flex; align-items: flex-end; gap: 10px;
  height: 160px; padding-top: 10px; overflow-x: auto; flex: 1;
  border-left: 1px solid var(--border);
}
.bar-group { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 34px; }
.bar-pair {
  display: flex; align-items: flex-end; gap: 3px;
  height: 130px;
}
.bar-seg { width: 13px; border-radius: 3px 3px 0 0; flex: 0 0 13px; }
.bar-seg.cash { background: var(--primary); }
.bar-seg.cashless { background: var(--success); }
.bar-label { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-soft); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.legend .cash { background: var(--primary); }
.legend .cashless { background: var(--success); }

/* ---------- модалка ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: 14px;
  max-width: 900px; width: 100%; max-height: 90vh;
  overflow: auto; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-head h2 { margin: 0; }
.modal-body { padding: 20px 22px; }
.modal-close {
  background: transparent; border: none; font-size: 22px;
  color: var(--text-muted); cursor: pointer; padding: 4px 10px;
  border-radius: 8px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* ---------- прочее ---------- */
.muted { color: var(--text-muted); font-size: 13px; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 12px; font-weight: 600;
}
.tag-open { background: var(--success-soft); color: var(--success); }
.tag-closed { background: var(--danger-soft); color: var(--danger); }

.shift-list-item {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 8px; cursor: pointer;
  background: var(--surface); transition: background .15s, border-color .15s;
}
.shift-list-item:hover { background: var(--surface-2); border-color: var(--primary); }
.shift-list-item .s-date { font-weight: 600; min-width: 100px; }
.shift-list-item .s-master { flex: 1; }
.shift-list-item .s-amount { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- страница входа ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 130%);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}
.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 20px; font-weight: 700;
  margin-bottom: 24px;
}
.login-card label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--text-muted); margin-bottom: 16px;
}
.login-card input {
  width: 100%; font-size: 15px; padding: 11px 12px;
}
.login-card .btn { width: 100%; margin-top: 6px; font-size: 15px; padding: 11px; }
.login-error {
  color: var(--danger); background: var(--danger-soft);
  border-radius: 8px; padding: 10px 12px; font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- нижняя панель вкладок (моб.) ---------- */
.tabbar { display: none; }

/* ---------- адаптив под телефон ---------- */
@media (max-width: 640px) {
  :root { --topbar-h: 54px; }
  .topbar-inner { padding: 0 12px; gap: 10px; }
  .nav { display: none; }

  .container {
    padding: 16px 12px 100px;
    padding-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 16px);
  }
  h1 { font-size: 19px; }

  .card { padding: 14px; }

  .shift-header { gap: 14px; }
  .shift-actions { margin-left: 0; width: 100%; }
  .shift-actions .btn { flex: 1; }

  .form-row { flex-direction: column; align-items: stretch; }
  .form-row input, .form-row select, .form-row label { min-width: 0; width: 100%; }
  .form-row button { width: 100%; }

  input, select, .btn { font-size: 16px; }
  .btn { min-height: 40px; }

  .totals { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }

  .dash-filters { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .dash-filters .btn { flex: 0 0 auto; padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .dash-custom { flex-wrap: nowrap; overflow-x: auto; }
  .dash-custom input[type="date"] { flex: 1; min-width: 130px; }

  .modal { max-height: 100vh; border-radius: 0; }
  .modal-backdrop { padding: 0; }

  .shift-list-item { flex-wrap: wrap; gap: 8px 16px; }
  .shift-list-item .s-master { min-width: 100%; order: 3; }

  .tabbar {
    display: flex;
    position: fixed;
    left: 10px; right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(22, 29, 52, 0.85);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    gap: 2px;
  }
  .tab-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    background: transparent; border: none; color: var(--text-muted);
    padding: 7px 2px 6px;
    border-radius: 16px;
    font-size: 10px; font-weight: 600;
    font-family: inherit;
    cursor: pointer;
  }
  .tab-btn .tab-icon { display: flex; }
  .tab-btn .tab-icon svg { width: 21px; height: 21px; }
  .tab-btn.active { color: var(--primary); background: var(--primary-soft); }
  .tab-btn.hidden { display: none; }
}