/* Cards & Panels (Max Depth <= 2, Zero Boxitis) */
.card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-md); padding: var(--space-5); box-shadow: var(--shadow-card); min-width: 0; }
.card-flex { display: flex; flex-direction: column; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.card-head > * { min-width: 0; }

.card-title { font-size: 16px; font-weight: 600; color: var(--text-ink); }
.muted { color: var(--text-secondary); font-size: 13px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }

.num, th.num, td.num { text-align: end; font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.kopeks-muted { color: var(--text-secondary); font-weight: 400; font-size: 0.85em; }

.ellipsis {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Verdict Strip */
.verdict-strip { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--r-md); display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); overflow: hidden; }
.verdict-cell { padding: var(--space-4) var(--space-5); border-right: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.verdict-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.verdict-value { font-size: 22px; line-height: 1.2; font-weight: 700; color: var(--text-ink); font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.verdict-value.is-danger { color: var(--danger-ink); }

/* Buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background-color 150ms var(--ease-aaa), border-color 150ms var(--ease-aaa), transform 90ms var(--ease-aaa);
}

.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--brand-ring); }
.btn:active:not(:disabled) { transform: scale(0.97); background: var(--bg-press); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg, .nav-item svg, .mobile-nav-btn svg { flex-shrink: 0; }

.btn.active,
.btn[aria-pressed="true"] { background: var(--brand-solid); color: var(--text-on-solid); border-color: var(--brand-solid); }

.btn-primary { background: var(--brand-accent); color: var(--text-on-solid); border-color: var(--brand-accent); }
.btn-primary:hover:not(:disabled) { background: var(--brand-accent-hover); border-color: var(--brand-accent-hover); }
.btn-solid { background: var(--brand-solid); color: var(--text-on-solid); border-color: var(--brand-solid); }
.btn-solid:hover:not(:disabled) { background: var(--brand-solid-hover); border-color: var(--brand-solid-hover); }

.btn-danger { background: var(--bg-surface); color: var(--danger-ink); border-color: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger-ink); }
.btn-dark-ghost { background: rgba(255, 255, 255, 0.08); color: var(--text-on-solid); border-color: rgba(255, 255, 255, 0.22); }
.btn-dark-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.4); }
.btn-dark-ghost.active { background: var(--brand-accent); border-color: var(--brand-accent); color: var(--text-on-solid); }

.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn-terminal { min-height: 48px; padding: 12px 18px; font-size: 15px; font-weight: 600; }
.btn-icon { min-width: 40px; padding: 8px; }

.btn.is-loading .btn-label {
  opacity: 0;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 650ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Segmented Controls (<= 4 options) */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.seg-btn {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms var(--ease-aaa), color 140ms var(--ease-aaa);
}

.seg-btn:hover { background: var(--bg-hover); }

.seg-btn.active, .seg-btn[aria-pressed="true"] { background: var(--brand-solid); color: var(--text-on-solid); border-color: var(--brand-solid); }
.seg-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Form Controls & Custom Select */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color 140ms var(--ease-aaa), box-shadow 140ms var(--ease-aaa);
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  outline: none;
  border-color: var(--brand-ring);
  box-shadow: var(--focus-ring);
}

.select {
  appearance: none;
  max-width: 420px;
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2311091C' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px 16px;
}

.select option {
  background: #FFFFFF;
  color: #11091C;
}

@supports (appearance: base-select) {
  .select,
  .select::picker(select) { appearance: base-select; }
  .select::picker-icon { display: none; }
  .select::picker(select) {
    background: var(--bg-surface);
    border: 1px solid var(--border-control);
    border-radius: var(--r-sm);
    padding: 4px;
    box-shadow: var(--shadow-float);
  }
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  border: 1px solid #C2B8DC;
  background: #FFFFFF;
  color: #11091C;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms var(--ease-aaa), border-color 150ms var(--ease-aaa);
}
input[type="file"]::file-selector-button:hover { background: var(--bg-hover); border-color: var(--brand-ring); }

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand-accent);
  cursor: pointer;
}

/* Badges (Exception-Only Color, Zero .dot) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-subtle { background: var(--bg-subtle); border-color: var(--border-subtle); color: var(--text-secondary); }
.badge-solid { background: var(--brand-solid); border-color: var(--brand-solid); color: var(--text-on-solid); }
.badge-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-ink); }

.badge-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-ink);
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  background: var(--bg-surface);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table thead th.num {
  text-align: end;
}

.data-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; color: var(--text-primary); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.is-clickable { cursor: pointer; }
.data-table tbody tr.is-clickable:hover td { background: var(--bg-canvas); }
.grid-2 .data-table { table-layout: fixed; width: 100%; min-width: 440px; }
.grid-2 .data-table th, .grid-2 .data-table td { padding: 9px 10px; }
.grid-2 .data-table td .badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

/* Local interpolate-size only on collapsible archive/accordion */
.archive-collapse {
  interpolate-size: allow-keywords;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.archive-summary {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  cursor: pointer;
  background: var(--bg-canvas);
}

/* Diff & Two-Layer Draft */
.diff-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.brief-box { background: var(--bg-subtle); border-left: 3px solid var(--brand-accent); border-radius: var(--r-xs); padding: 10px 12px; font-size: 13px; color: var(--text-primary); min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.client-draft-box { background: var(--bg-surface); border: 1px solid var(--border-control); border-radius: var(--r-xs); padding: 10px 12px; font-size: 14px; color: var(--text-ink); min-width: 0; overflow-wrap: anywhere; word-break: break-word; }

.leak-banner,
.error-banner {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  color: var(--danger-ink);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-state {
  padding: var(--space-6);
  text-align: center;
  border: 1px dashed var(--border-control);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

/* Drawer & Modal Dialog */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(13, 7, 23, 0.44);
}

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41; width: min(620px, 100vw);
  background: var(--bg-surface); border-left: 1px solid var(--border-subtle); box-shadow: var(--shadow-float);
  display: flex; flex-direction: column; overscroll-behavior: contain; animation: slideInRight 260ms var(--ease-drawer);
}

@keyframes slideInRight {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.drawer-header, .dialog-header {
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3);
}
.drawer-title, .dialog-title { font-size: 17px; line-height: 1.3; }
.drawer-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.drawer-body, .dialog-body {
  flex: 1 1 auto; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4);
}
.drawer-body > *, .dialog-body > * {
  flex-shrink: 0;
}
.drawer-footer, .dialog-footer {
  padding: var(--space-4) var(--space-5) calc(var(--space-4) + var(--safe-bottom)); border-top: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; background: var(--bg-surface);
}

.modal-dialog {
  padding: 0; border: 1px solid var(--border-subtle); border-radius: var(--r-lg);
  width: min(500px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-float);
}
.modal-dialog:modal { overscroll-behavior: contain; }
.modal-dialog::backdrop { background: rgba(13, 7, 23, 0.52); overflow: hidden; overscroll-behavior: contain; }

.dialog-box {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 34px);
}

/* Toasts */
.toast-region {
  position: fixed; right: var(--space-4); bottom: calc(var(--space-4) + var(--safe-bottom)); z-index: 60;
  display: flex; flex-direction: column; gap: var(--space-2); max-width: min(380px, calc(100vw - 24px)); pointer-events: none;
}

.toast {
  pointer-events: auto; background: var(--brand-solid); color: var(--text-on-solid); border-radius: var(--r-sm);
  padding: 12px 14px; font-size: 13px; box-shadow: var(--shadow-float);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.toast.toast-error { background: var(--danger-solid); }

/* F5 Photos Grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-3); }
.photo-tile { border: 1px solid var(--border-subtle); border-radius: var(--r-sm); overflow: hidden; background: var(--bg-canvas); display: block; text-decoration: none; }
.photo-tile img, .photo-thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.photo-fallback { aspect-ratio: 4 / 3; display: grid; place-items: center; padding: var(--space-3); text-align: center; }
.print-sheet { display: none; }

/* Settings, TG Accounts, Live Messages & Forwarding */
.warn-banner { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--r-sm); padding: 12px 14px; color: var(--warn-ink); font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.ok-banner { background: var(--bg-subtle); border: 1px solid var(--brand-ring); border-radius: var(--r-sm); padding: 10px 12px; color: var(--text-ink); font-size: 13px; }

.kv-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); padding: 4px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.kv-row:last-child { border-bottom: none; }
.kv-key { color: var(--text-secondary); font-weight: 500; }
.kv-val { color: var(--text-ink); font-weight: 500; text-align: end; min-width: 0; overflow-wrap: anywhere; }

.input-row { display: flex; align-items: center; gap: 8px; }
.input-row .input { flex: 1 1 auto; min-width: 0; }

.step-pills { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.step-pill { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border-subtle); background: var(--bg-canvas); color: var(--text-secondary); }
.step-pill.is-active { background: var(--brand-solid); border-color: var(--brand-solid); color: var(--text-on-solid); }
.step-pill.is-done { background: var(--bg-subtle); border-color: var(--brand-ring); color: var(--text-ink); }

.settings-list { display: flex; flex-direction: column; }
.settings-item { padding: var(--space-4) 0; border-bottom: 1px solid var(--border-subtle); display: flex; flex-direction: column; gap: var(--space-3); }
.settings-item:first-child { padding-top: 0; }
.settings-item:last-child { padding-bottom: 0; border-bottom: none; }
.settings-item-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-3); align-items: end; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }

.msg-feed { display: flex; flex-direction: column; gap: 8px; max-height: 290px; overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; margin-bottom: var(--space-3); }
.msg-row { padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--border-subtle); background: var(--bg-canvas); display: flex; flex-direction: column; gap: 6px; }
.msg-row.is-client { border-left: 3px solid var(--brand-accent); background: var(--bg-subtle); }
.msg-row.is-me { border-left: 3px solid var(--brand-solid); background: var(--bg-surface); }
.msg-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.msg-meta { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.msg-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); cursor: pointer; min-height: 28px; }
.msg-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand-accent); cursor: pointer; }
.msg-text { font-size: 14px; color: var(--text-ink); white-space: pre-wrap; overflow-wrap: anywhere; }

.forward-box { border-top: 1px solid var(--border-subtle); padding-top: var(--space-3); margin-top: var(--space-2); display: flex; flex-direction: column; gap: var(--space-3); }
.helper-text { font-size: 12px; color: var(--text-secondary); }

@media (max-width: 900px) {
  .mobile-nav { touch-action: pan-x; }
  .mobile-nav-btn { min-width: 72px; min-height: 46px; padding: 6px 10px; }
}

@media (max-width: 768px) {
  .drawer {
    top: auto; left: 0; right: 0; width: 100%; max-height: 92dvh;
    border-left: none; border-top: 1px solid var(--border-subtle); border-radius: 20px 20px 0 0;
  }
  .diff-grid { grid-template-columns: minmax(0, 1fr); }
  .toast-region { left: 12px; right: 12px; bottom: calc(74px + var(--safe-bottom)); max-width: none; }
  .btn:not(.btn-terminal), .btn-sm, .seg-btn, .input, .select { min-height: 44px; }
  .btn.btn-terminal { min-height: 48px; }
}
