/* ==========================================================================
   ТЕМИ ТА ДИЗАЙН-ТОКЕНИ
   ========================================================================== */
:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --text: #1b1b1b;
  --muted: #7a6f66;
  --border: #eadfd4;
  --accent: #ff9f0a;
  --accentText: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 10px 26px rgba(0, 0, 0, .08);
}

/* Автоперемикання на темну тему */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110e;
    --surface: #1e1915;
    --text: #ffffff;
    --muted: #b2a79d;
    --border: #2b2621;
    --accent: #ffb340;
    --accentText: #1b1b1b;
  }
}

/* ==========================================================================
   БАЗА
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, Roboto, Segoe UI, Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

.browser-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background: linear-gradient(160deg, #f7f4ef 0%, #f0eadf 35%, #e9e0d4 70%, #e2d7ca 100%);
}

.browser-auth.hidden {
  display: none !important;
}

.browser-auth-card {
  width: min(420px, 100%);
  background: #ffffff;
  color: #1b1b1b;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 520px;
}

.browser-auth-card h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
}

.auth-tabs {
  display: inline-flex;
  background: #f3f0ea;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 10px;
  border: 1px solid #eadfd4;
  width: 100%;
  box-sizing: border-box;
}

.auth-tab {
  flex: 1;
  text-align: center;
  border: none;
  background: transparent;
  color: #7a6f66;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s ease;
}

.auth-tab.active {
  background: #ff9f0a;
  color: #fff;
  box-shadow: 0 12px 28px rgba(255, 159, 10, 0.3);
}

.auth-code {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  background: #f3f0ea;
  border: 1px solid #eadfd4;
  padding: 16px 18px;
  border-radius: 14px;
}

.auth-code-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.auth-meta {
  font-size: 14px;
  color: #7a6f66;
}

.auth-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-status {
  min-height: 24px;
  font-size: 14px;
  color: #7a6f66;
}

.auth-status.error {
  color: #d14343;
}

#passwordAuth h1,
#tgAuthBlock h1 {
  margin-top: 0;
  margin-bottom: 12px;
}

.auth-hint {
  margin: 4px 0 18px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.auth-form {
  display: grid;
  gap: 6px;
}

.auth-label {
  font-size: 14px;
  color: #7a6f66;
  margin-top: 4px;
}

.auth-submit {
  margin-top: 35px;
  width: 100%;
  min-height: 46px;
  height: 46px;
  padding: 0 16px;
  background: var(--accent) !important;
  color: var(--accentText) !important;
  border: 1px solid var(--accent) !important;
  box-shadow: 0 10px 24px rgba(255, 159, 10, .22);
}

.auth-form input {
  height: 46px;
  min-height: 46px;
}

.password-auth {
  display: grid;
  gap: 14px;
  margin-top: 10px;
}

.password-auth input {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 10px 12px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

.password-toggle {
  margin-top: 12px;
  color: #e2e8f0;
  font-size: 14px;
}

.password-toggle input {
  margin-right: 8px;
}

#tgAuthBlock .auth-code {
  margin-top: 10px;
  margin-bottom: 10px;
}

#tgAuthBlock .auth-meta {
  margin-top: 8px;
}

#browserAuthRefresh {
  background: var(--accent);
  color: var(--accentText);
  border: 1px solid var(--accent);
  box-shadow: 0 10px 24px rgba(255, 159, 10, .22);
}

#tgAuthBlock .auth-actions {
  margin-top: 20px;
}

#tgAuthBlock .auth-status {
  margin-top: 10px;
}

.hidden {
  display: none !important;
}

.container {
  min-height: 100vh;
  padding: 36px 12px calc(36px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  width: 100vw;
  max-width: 100%;
  overflow-x: hidden;
}

.container.hidden {
  display: none !important;
}

.panel {
  width: min(520px, 100%);
  margin: 0 auto;
  padding: clamp(12px, 4vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-sizing: border-box;
}

@media (max-width: 640px) {
  .container {
    min-height: auto;
    padding: 20px 12px calc(24px + env(safe-area-inset-bottom));
    display: block;
    width: 100vw;
  }

  .panel {
    width: 100%;
    padding: 0;
  }
}

/* ==========================================================================
   ЗАГОЛОВКИ
   ========================================================================== */
.title-large {
  font-size: 28px;
  line-height: 1.2;
  font-weight: 700;
  margin: 6px 4px 14px;
}

.title-large.center {
  text-align: center;
}

/* ==========================================================================
   TOP BAR (базовий) — як у робочій версії
   ========================================================================== */
.bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin: 6px 0 24px;
}

.bar-left,
.bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-left {
  justify-content: flex-start;
}

.bar-right {
  justify-content: flex-end;
}

.bar-center {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.bar-edge .bar-center {
  justify-content: center;
  align-items: center;
}

.bar-edge .bar-left {
  justify-content: flex-start;
}

.bar-edge .bar-right {
  justify-content: flex-end;
}

.bar-title {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .01em;
}

.bar-title+.bar-subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.bar .btn {
  min-width: 0;
}

/* ==========================================================================
   ДВОРЯДКОВИЙ МАКЕТ BAR — заголовок зверху, кнопки нижче по краях
   ========================================================================== */
.bar.split-rows {
  /* 3 колонки: лівий край — центр — правий край */
  grid-template-columns: 1fr auto 1fr;
  /* 2 рядки: 1-й заголовок, 2-й кнопки */
  grid-template-rows: auto auto;
  row-gap: 10px;
}

.bar.split-rows .bar-center {
  /* центр займає весь 1-й рядок */
  grid-column: 1 / 4;
  grid-row: 1;
  justify-self: center;
  align-self: start;
}

.bar.split-rows .bar-left {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  align-self: end;
}

.bar.split-rows .bar-right {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  align-self: end;
}

/* ==========================================================================
   УТИЛІТИ
   ========================================================================== */
.hidden {
  display: none !important;
}

/* ==========================================================================
   ГРУПИ/КАРТКИ
   ========================================================================== */
.group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: grid;
  gap: 12px;
}

.group-form {
  gap: 10px;
}

.caption {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 0 6px 4px 6px;
}

/* ==========================================================================
   INPUTS/TEXTAREA
   ========================================================================== */
input,
textarea {
  appearance: none;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 65%, var(--bg));
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  box-sizing: border-box;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

/* ==========================================================================
   КНОПКИ
   ========================================================================== */
.stack-buttons {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accentText);
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(255, 159, 10, .22);
}

.btn-outline {
  background: color-mix(in oklab, var(--surface) 92%, var(--bg));
  border-color: var(--border);
}

.btn-secondary {
  background: color-mix(in oklab, var(--surface) 92%, var(--bg));
  border-color: color-mix(in oklab, var(--border) 70%, transparent);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text);
}

.btn-accent {
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent) 85%, #ffffff), var(--accent));
  color: var(--accentText);
  border: none;
  box-shadow: 0 14px 28px rgba(255, 159, 10, .3);
}

.btn-full {
  width: 100%;
}

.btn-disabled {
  opacity: .75;
}

.btn-sm {
  min-height: 34px;
  font-size: 14px;
  padding: 0 14px;
}

.btn-icon {
  min-height: 36px;
  width: 38px;
  padding: 0;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  padding: 0;
  min-height: auto;
  height: auto;
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  border: none;
  box-shadow: 0 12px 22px rgba(220, 38, 38, .28);
}

.btn-add {
  margin-top: 18px;
  font-weight: 700;
  letter-spacing: .02em;
}

.btn-add-icon {
  font-size: 22px;
  line-height: 1;
}

.btn-add-text {
  font-size: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 92%, var(--bg));
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}

.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accentText);
  box-shadow: 0 10px 22px rgba(255, 159, 10, .24);
}

/* ==========================================================================
   РЕЗУЛЬТАТИ / ЕЛЕМЕНТИ
   ========================================================================== */
.results {
  margin-top: 10px;
  display: grid;
  gap: 14px;
}

#camerasList.results {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.camera-add {
  display: grid;
  gap: 10px;
}

.camera-add-title {
  font-weight: 700;
  font-size: 16px;
}

.camera-add-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.camera-add input {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px;
  font-size: 14px;
}

.camera-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  align-content: start;
}

.camera-list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.camera-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #0f172a;
  border: 1px solid rgba(0, 0, 0, .08);
  aspect-ratio: 16 / 9;
}

.camera-frame video,
.camera-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.camera-frame video {
  aspect-ratio: 16 / 9;
  background: #0f172a;
  border-radius: 12px;
}

.camera-frame .camera-fallback {
  position: absolute;
  inset: 0;
  transition: opacity .2s ease;
  background: #0f172a;
}

.camera-frame .camera-fallback.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.camera-history-panel {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.camera-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.camera-history-title {
  font-weight: 700;
  font-size: 18px;
}

.history-mode {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: color-mix(in oklab, var(--surface) 92%, var(--bg));
  border-radius: 12px;
  border: 1px solid var(--border);
}

.camera-history-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  align-items: center;
}

.history-date-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in oklab, var(--surface) 92%, var(--bg));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  justify-content: space-between;
}

.history-current-date {
  font-weight: 700;
  min-width: 140px;
  text-align: center;
}

.history-date-picker {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.history-date-picker input {
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 14px;
}

.camera-history-hint {
  color: var(--muted);
  font-size: 14px;
}

.history-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.history-thumb {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 12px rgba(0, 0, 0, .06);
  background: #0f172a;
  padding: 10px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.history-thumb a {
  text-decoration: none;
}

.history-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(239, 68, 68, .9);
  color: #fff;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.history-thumb .label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  padding: 4px 8px;
  font-size: 12px;
}

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  gap: 8px;
}

.item-title {
  font-size: 18px;
  margin-bottom: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.item .meta {
  color: var(--muted);
  font-size: 14px;
  margin: 2px 0;
}

.item .meta.big {
  color: var(--text);
  font-size: 16px;
}

.item .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: color-mix(in oklab, var(--accent) 12%, transparent);
  padding: 3px 8px;
  border-radius: 8px;
  letter-spacing: .08em;
}

.item-action {
  margin-top: 12px;
}

.item-detail {
  gap: 12px;
}

.actions-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.actions-grid .btn {
  flex: 1 1 45%;
  min-width: 140px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  padding: 12px 4px;
  text-align: center;
}

/* ==========================================================================
   НОТАТКИ / ІСТОРІЯ
   ========================================================================== */
.notes-timeline {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

.note-view-block {
  background: color-mix(in oklab, var(--surface) 96%, var(--bg));
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4);
  display: grid;
  gap: 6px;
}

.note-view-text {
  white-space: pre-wrap;
  font-size: 14px;
}

.notes-edit {
  display: grid;
  gap: 14px;
}

.note-edit-block {
  background: color-mix(in oklab, var(--surface) 96%, var(--bg));
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.note-edit-actions {
  display: flex;
  justify-content: flex-end;
}

.note-edit-block textarea {
  min-height: 80px;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-heading {
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  color: var(--muted);
}

.history-item {
  background: color-mix(in oklab, var(--surface) 96%, var(--bg));
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
}

.history-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-item-title {
  font-weight: 600;
  font-size: 15px;
}

.history-item-meta {
  font-size: 13px;
  color: var(--muted);
}

.history-toggle {
  margin-left: auto;
}

.history-diff {
  background: color-mix(in oklab, var(--surface) 96%, var(--bg));
  border: 1px solid color-mix(in oklab, var(--border) 75%, transparent);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 10px;
  font-size: 14px;
}

.history-diff.hidden {
  display: none;
}

.history-diff-section {
  display: grid;
  gap: 6px;
}

.history-diff-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.history-diff-grid {
  display: grid;
  gap: 4px;
}

.history-diff-grid div {
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-diff-grid span {
  font-weight: 600;
}

.history-diff-grid code {
  background: color-mix(in oklab, var(--surface) 90%, var(--bg));
  padding: 3px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.history-diff-notes {
  display: grid;
  gap: 10px;
}

.history-diff-note-block {
  background: color-mix(in oklab, var(--surface) 92%, var(--bg));
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
}

.history-diff-note-header {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.history-diff-note-block ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 2px;
}

.history-diff-note-block li {
  list-style: disc;
  font-size: 13px;
}

.history-diff-note-block.changed li {
  list-style: none;
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-diff-note-block.current {
  border-style: dashed;
}

.history-diff-note-block.changed li .arrow {
  opacity: .6;
}

.history-diff-note-block.changed li .old {
  color: var(--muted);
}

.history-diff-note-block.changed li .new {
  font-weight: 600;
}

/* ==========================================================================
   МЕНЕДЖМЕНТ-СПИСОК
   ========================================================================== */
.manage-list {
  display: grid;
  gap: 12px;
}

.manage-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.manage-info {
  display: grid;
  gap: 4px;
  min-width: 200px;
}

.manage-name {
  font-weight: 600;
  font-size: 16px;
}

.manage-meta {
  font-size: 13px;
  color: var(--muted);
}

.manage-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.manage-search {
  position: relative;
  margin: 16px 0 12px;
}

.manage-search input {
  width: 100%;
  padding: 12px 44px 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  box-shadow: var(--shadow);
}

.manage-search input::placeholder {
  color: var(--muted);
}

.manage-search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
}

.manage-search-clear.hidden {
  opacity: 0;
  pointer-events: none;
}

.manage-search-clear:focus {
  outline: none;
}

.manage-search-clear:hover {
  color: var(--text);
}

.manage-actions .manage-btn {
  min-height: 38px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.manage-actions .manage-btn.btn-secondary {
  background: linear-gradient(135deg,
      color-mix(in oklab, var(--surface) 96%, var(--bg)),
      color-mix(in oklab, var(--surface) 88%, var(--bg)));
  border: 1px solid color-mix(in oklab, var(--border) 65%, transparent);
  box-shadow: 0 6px 12px rgba(15, 23, 42, 0.1);
}

.manage-actions .manage-btn.btn-danger {
  background: linear-gradient(135deg, #f87171, #ef4444);
  border: none;
  color: #fff;
  box-shadow: 0 12px 26px rgba(239, 68, 68, 0.32);
}

.manage-actions .manage-btn:active {
  transform: translateY(1px);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--accent) 18%, transparent);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: rgba(34, 197, 94, 0.18);
  color: #166534;
}

.badge-muted {
  background: rgba(148, 163, 184, 0.18);
  color: var(--muted);
}

.badge-danger {
  background: rgba(248, 113, 113, 0.18);
  color: #7f1d1d;
}

/* ==========================================================================
   МОДАЛЬНЕ (LOCK)
   ========================================================================== */
.lock {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .06);
  backdrop-filter: blur(2px);
}

.lock.hidden {
  display: none;
}

.lock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 16px;
  width: min(520px, 92vw);
  text-align: center;
}

.lock-title {
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 6px;
}

.lock-text {
  color: var(--muted);
  margin-bottom: 12px;
}

/* ==========================================================================
   COMBOBOX / SUGGEST
   ========================================================================== */
.combobox {
  position: relative;
}

.combobox .suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 999;
  min-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
}

.combobox .suggest ul {
  list-style: none;
  margin: 6px 0;
  padding: 0;
}

.combobox .suggest li {
  padding: 10px 12px;
  cursor: pointer;
  outline: none;
}

.combobox .suggest li:hover,
.combobox .suggest li:focus {
  background: color-mix(in oklab, var(--accent) 12%, transparent);
}

/* ==========================================================================
   РЕСПОНСИВ
   ========================================================================== */
@media (max-width: 540px) {

  /* Перебудова тільки для ЗВИЧАЙНИХ барів (не split-rows) */
  .bar:not(.split-rows) {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .bar:not(.split-rows) .bar-left {
    justify-content: flex-start;
  }

  .bar:not(.split-rows) .bar-center {
    justify-content: center;
    text-align: center;
  }

  .bar:not(.split-rows) .bar-right {
    justify-content: flex-end;
  }

  /* Для split-rows зберігаємо дворядкову сітку і на мобільних */
  .bar.split-rows {
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto auto;
    row-gap: 10px;
  }

  .bar.split-rows .bar-center {
    grid-column: 1 / 4;
    grid-row: 1;
    justify-self: center;
    align-self: start;
  }

  .bar.split-rows .bar-left {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
    align-self: end;
  }

  .bar.split-rows .bar-right {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    align-self: end;
  }
}

@media (min-width: 540px) {
  .container {
    padding: 28px 24px calc(32px + env(safe-area-inset-bottom));
  }

  .panel {
    max-width: 700px;
    gap: 22px;
  }

  .group {
    padding: 18px 20px;
    border-radius: 20px;
    gap: 16px;
  }

  .group-form {
    gap: 14px;
  }

  .title-large {
    font-size: 30px;
  }

  .stack-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .btn {
    min-height: 50px;
    font-size: 17px;
  }

  .btn-add {
    justify-self: end;
    width: auto;
    padding-inline: 28px;
  }

  .suggest {
    border-radius: 16px;
  }
}

@media (min-width: 768px) {
  .panel {
    max-width: 920px;
  }

  .results {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }

  .item {
    padding: 20px;
    border-radius: 20px;
  }

  .item-title {
    font-size: 20px;
  }

  .item .meta.big {
    font-size: 17px;
  }

  .actions-grid {
    gap: 12px;
  }

  .actions-grid .btn {
    min-width: 160px;
  }

  .notes-timeline,
  .notes-edit,
  .history-list {
    gap: 16px;
  }

  .note-view-block,
  .note-edit-block,
  .history-item {
    padding: 16px 18px;
    border-radius: 18px;
  }

  .bar {
    gap: 18px;
    margin-bottom: 18px;
  }

  .bar-title {
    font-size: 22px;
  }
}

@media (min-width: 1024px) {
  body {
    font-size: 17px;
  }

  .container {
    padding: 36px 40px calc(36px + env(safe-area-inset-bottom));
  }

  .panel {
    max-width: 1100px;
  }

  .stack-buttons {
    gap: 14px;
  }

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

  .btn {
    min-height: 54px;
    font-size: 18px;
  }

  .btn-add {
    margin-top: 22px;
  }

  .combobox input {
    font-size: 18px;
  }

  textarea {
    min-height: 110px;
    font-size: 17px;
  }

  .note-view-meta,
  .history-item-meta {
    font-size: 13px;
    letter-spacing: .01em;
  }
}
