/* ============================================================
   Sheets – Bottom Sheets, Modals, Forms, Toasts, Confirm, Loading
   ============================================================ */

/* ─── Sheet Overlay ───────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sheet-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ─── Sheet ───────────────────────────────────────────────── */
.sheet {
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 0 18px calc(18px + var(--safe-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  box-sizing: border-box;
  /* Vertical scroll only — never let inner content force horizontal scroll */
  overscroll-behavior: contain;
}

@media (min-width: 768px) {
  .sheet {
    max-width: 600px;
    padding: 0 24px calc(24px + var(--safe-bottom));
  }
}

@media (max-width: 480px) {
  .sheet {
    padding: 0 14px calc(14px + var(--safe-bottom));
    border-radius: 22px 22px 0 0;
  }
  .sheet-header {
    padding: 14px 4px;
  }
}

.sheet-overlay.open .sheet {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sheet-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.sheet-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface-2);
  font-size: 16px;
  transition: color 0.2s ease;
}

.sheet-close:hover {
  color: var(--text);
}

/* ─── Form Fields ─────────────────────────────────────────── */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  min-width: 0;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.25s ease;
}

.form-input:focus {
  border-color: var(--brand);
}

.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-inline-end: 36px;
  transition: border-color 0.25s ease;
}

[dir="rtl"] .form-select {
  background-position: left 12px center;
}

.form-select:focus {
  border-color: var(--brand);
}

.form-textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  min-height: 80px;
  resize: vertical;
  transition: border-color 0.25s ease;
}

.form-textarea:focus {
  border-color: var(--brand);
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

#qct-person-names-field {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 480px) {
  #qct-person-names-field {
    grid-template-columns: 1fr;
  }
}

/* ─── Invoice Line Row ───────────────────────────────────── */
.inv-line-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px 80px 80px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.inv-line-row .form-input {
  padding: 8px 10px;
  font-size: 13px;
}
.inv-line-row .inv-line-total {
  font-size: 12px;
  font-weight: 700;
  text-align: end;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inv-line-row .inv-line-remove {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--expense-glow);
  color: var(--expense);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
}
@media (max-width: 540px) {
  .inv-line-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px;
    grid-template-areas:
      "desc  desc  remove"
      "qty   price total";
    row-gap: 6px;
  }
  .inv-line-row .inv-line-desc   { grid-area: desc; }
  .inv-line-row .inv-line-remove { grid-area: remove; align-self: center; }
  .inv-line-row .inv-line-qty    { grid-area: qty; }
  .inv-line-row .inv-line-price  { grid-area: price; }
  .inv-line-row .inv-line-total  { grid-area: total; text-align: end; padding-inline-end: 4px; }
}

/* ─── Type Tabs (Income / Expense / Transfer) ─────────────── */
.type-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0;
  background: transparent;
  margin-bottom: 16px;
}

.type-tab {
  position: relative;
  padding: 14px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 2px solid var(--border);
  transition: transform .18s ease, background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
  user-select: none;
  overflow: hidden;
}

.type-tab-icon {
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  transition: background-color .2s ease, color .2s ease, transform .2s ease;
}

.type-tab-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .2px;
  line-height: 1.1;
}

/* Inactive: subtle per-type icon tint so each option still reads at a glance */
.type-tab[data-type="expense"]  .type-tab-icon { background: hsla(0, 80%, 60%, .14);  color: var(--expense); }
.type-tab[data-type="income"]   .type-tab-icon { background: hsla(var(--brand-hue), 72%, 40%, .14); color: var(--brand); }
.type-tab[data-type="transfer"] .type-tab-icon { background: hsla(238, 84%, 67%, .14); color: var(--transfer); }

.type-tab:hover:not(.active) {
  border-color: var(--text-muted);
  color: var(--text);
  transform: translateY(-1px);
}

/* Active: full-color card with elevation and a check marker */
.type-tab.active {
  color: #FFF;
  transform: translateY(-2px);
}

.type-tab.active .type-tab-icon {
  background: rgba(255, 255, 255, .22);
  color: #FFF;
  transform: scale(1.06);
}

.type-tab.active::after {
  content: '✓';
  position: absolute;
  top: 6px;
  inset-inline-end: 8px;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #FFF;
  background: rgba(255, 255, 255, .25);
  border-radius: 50%;
  line-height: 1;
}

.type-tab-expense.active {
  background: var(--expense);
  border-color: var(--expense);
  box-shadow: 0 8px 18px -6px hsla(0, 80%, 60%, .55);
}

.type-tab-income.active {
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 8px 18px -6px hsla(var(--brand-hue), 72%, 40%, .55);
}

.type-tab-transfer.active {
  background: var(--transfer);
  border-color: var(--transfer);
  box-shadow: 0 8px 18px -6px hsla(238, 84%, 67%, .5);
}

@media (max-width: 380px) {
  .type-tab { padding: 12px 6px 10px; gap: 6px; }
  .type-tab-icon { width: 34px; height: 34px; font-size: 19px; }
  .type-tab-label { font-size: 12px; }
}

/* ─── Mode Pill (Actual / Planned) ─────────────────────────── */
.mode-pill {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
  margin-bottom: 16px;
  align-self: flex-start;
}

.mode-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s ease;
}

.mode-pill-btn.active {
  background: var(--brand);
  color: #FFF;
  box-shadow: 0 2px 8px hsla(var(--brand-hue), 72%, 40%, .3);
}

.mode-pill-btn:hover:not(.active) { color: var(--text); }

/* ─── Form Section Divider ─────────────────────────────────── */
.form-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-faint);
  margin: 8px 0 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.form-section:first-child { border-top: none; padding-top: 0; }

/* ─── Form Toggle (Simple/Advanced) ──────────────────────── */
.form-toggle-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface-2);
  border: none;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.form-toggle-btn:hover {
  color: var(--brand);
  background: var(--brand-glow);
}
.form-toggle-btn.active {
  color: var(--brand);
  background: var(--brand-glow);
}
.form-toggle-btn .toggle-icon-advanced { display: none; }
.form-toggle-btn .toggle-icon-simple { display: block; }
.form-toggle-btn.active .toggle-icon-advanced { display: block; }
.form-toggle-btn.active .toggle-icon-simple { display: none; }

/* ─── Form Advanced Section ──────────────────────────────── */
.form-advanced {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.35s ease, opacity 0.25s ease, margin 0.25s ease;
  margin-bottom: 0;
}
.form-advanced.open {
  max-height: 600px;
  opacity: 1;
  margin-bottom: 0;
}

/* ─── Toggle Switch ──────────────────────────────────────── */
.form-field-row {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.25s ease, background 0.25s ease;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--brand-glow);
  border-color: var(--brand);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--brand);
}
[dir="rtl"] .toggle-slider::before {
  left: auto;
  right: 2px;
}
[dir="rtl"] .toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(-20px);
}

/* ─── Amount Input ────────────────────────────────────────── */
.amount-wrapper {
  position: relative;
  margin-bottom: 18px;
}

.amount-input {
  width: 100%;
  padding: 22px 20px;
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(145deg, var(--surface-2), var(--surface));
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: all .25s ease;
  letter-spacing: -0.5px;
}

.amount-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px hsla(var(--brand-hue), 72%, 40%, .12);
  outline: none;
}

.amount-input.income   { border-color: hsla(var(--brand-hue), 72%, 40%, .35); }
.amount-input.expense  { border-color: hsla(0, 80%, 60%, .3); }
.amount-input.transfer { border-color: hsla(238, 84%, 67%, .35); }

.amount-input.income:focus   { border-color: var(--brand);    box-shadow: 0 0 0 4px hsla(var(--brand-hue), 72%, 40%, .18); }
.amount-input.expense:focus  { border-color: var(--expense);  box-shadow: 0 0 0 4px hsla(0, 80%, 60%, .18); }
.amount-input.transfer:focus { border-color: var(--transfer); box-shadow: 0 0 0 4px hsla(238, 84%, 67%, .18); }

.amount-currency {
  position: absolute;
  top: 50%;
  inset-inline-end: 20px;
  transform: translateY(-50%);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}

/* ─── Voice Command (opt-in via VOICECOMMAND env) ────────── */
.op-voice-btn {
  position: absolute;
  top: 50%;
  inset-inline-start: 14px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--brand);
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  z-index: 2;
}
.op-voice-btn:hover {
  background: var(--brand-glow);
  border-color: var(--brand);
}
.op-voice-btn.is-listening {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 0 hsla(var(--brand-hue), 72%, 40%, .55);
  animation: op-voice-pulse 1.2s ease-out infinite;
}
@keyframes op-voice-pulse {
  0%   { box-shadow: 0 0 0 0    hsla(var(--brand-hue), 72%, 40%, .55); }
  70%  { box-shadow: 0 0 0 14px hsla(var(--brand-hue), 72%, 40%, 0); }
  100% { box-shadow: 0 0 0 0    hsla(var(--brand-hue), 72%, 40%, 0); }
}
.amount-wrapper .amount-input { padding-inline-start: 64px; }

.op-voice-panel {
  margin: -6px 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px dashed hsla(var(--brand-hue), 72%, 40%, .3);
  display: grid;
  gap: 6px;
}
.op-voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.op-voice-langs {
  display: inline-flex;
  gap: 4px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.op-voice-lang {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  min-width: 32px;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.op-voice-lang.is-on {
  background: var(--brand);
  color: #fff;
}
.op-voice-lang:not(.is-on):hover {
  color: var(--text);
  background: var(--surface-hover);
}
.op-voice-status {
  font-size: 11px;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.op-voice-transcript {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-height: 18px;
  word-break: break-word;
}
.op-voice-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Primary Button ──────────────────────────────────────── */
.primary-btn {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, var(--brand), hsl(var(--brand-hue), 72%, 35%));
  color: #FFF;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  margin-top: 8px;
  box-shadow: 0 4px 14px hsla(var(--brand-hue), 72%, 40%, .25);
  transition: transform 0.2s ease, box-shadow 0.25s ease, opacity 0.25s ease;
}

.primary-btn:hover {
  box-shadow: 0 6px 20px hsla(var(--brand-hue), 72%, 40%, .35);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: translateY(0) scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ─── Confirm Dialog ──────────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.confirm-overlay.open {
  opacity: 1;
  visibility: visible;
}

.confirm-box {
  width: 90%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  animation: scale-in 0.3s ease;
}

.confirm-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.confirm-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.confirm-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

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

.confirm-cancel {
  flex: 1;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.25s ease;
}

.confirm-cancel:hover {
  border-color: var(--text-dim);
}

.confirm-danger {
  flex: 1;
  padding: 12px;
  background: var(--expense);
  border-radius: var(--radius-sm);
  color: #FFF;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.25s ease;
}

.confirm-danger:hover {
  opacity: 0.9;
}

/* ─── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text);
  z-index: 400;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  white-space: nowrap;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

.toast.ok {
  border-color: var(--brand);
}

.toast.err {
  border-color: var(--expense);
}

/* ─── Loading Bar ─────────────────────────────────────────── */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 500;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.loading-bar.active {
  opacity: 1;
}

.loading-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 30%;
  height: 100%;
  background: var(--brand);
  border-radius: 0 2px 2px 0;
  animation: loading-slide 1.2s ease infinite;
}

@keyframes loading-slide {
  0% {
    left: -30%;
  }
  100% {
    left: 100%;
  }
}

/* ─── Sheet Form Content Padding ──────────────────────────── */
.sheet .sheet-body {
  padding: 20px;
}

/* ─── Animations (referenced from layout) ─────────────────── */
@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
