/* ==========================================================================
   Tidy Bill — receipt-to-PDF tool styles
   ========================================================================== */

/* ── Layout ── */

.tb-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tb-workspace {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.tb-source-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tb-sidebar {
  flex: 0 0 148px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tb-preview-panel {
  flex: 0 0 400px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Drop zone & source canvas ── */

.tb-drop-zone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: 70vh;
  overflow: auto;
  background: rgba(0, 0, 0, 0.3);
  border: 2px dashed rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  transition:
    border-color var(--transition),
    background var(--transition);
  cursor: crosshair;
}

.tb-drop-zone.tb-drag-over {
  border-color: var(--accent);
  background: rgba(232, 164, 74, 0.06);
}

.tb-drop-zone.tb-has-image {
  align-items: flex-start;
  justify-content: flex-start;
  cursor: default;
}

.tb-drop-zone.tb-has-image.tb-mode-draw {
  cursor: crosshair;
}

.tb-drop-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
  pointer-events: none;
  user-select: none;
}

.tb-drop-zone.tb-has-image .tb-drop-hint {
  display: none;
}

.tb-drop-zone canvas {
  display: block;
}

/* ── Rotation controls ── */

.tb-rotation-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  flex-wrap: wrap;
}

.tb-rotation-controls input[type='range'] {
  flex: 1;
  min-width: 120px;
  accent-color: var(--accent);
}

/* ── Sidebar ── */

.tb-sidebar-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-subtle);
}

.tb-region-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.tb-region-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.tb-region-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.5rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition:
    border-color var(--transition),
    background var(--transition);
}

.tb-region-item:hover {
  border-color: rgba(232, 164, 74, 0.25);
  background: rgba(255, 255, 255, 0.07);
}

.tb-region-item.tb-region-item--active {
  border-color: var(--accent);
  background: rgba(232, 164, 74, 0.1);
}

.tb-region-item__label {
  flex: 1;
  color: var(--text-secondary);
}

.tb-region-item__delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.1rem;
  transition: color var(--transition);
}

.tb-region-item__delete:hover {
  color: #ff6666;
}

/* ── A4 preview panel ── */

.tb-page-tabs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tb-page-tab {
  padding: 0.25rem 0.7rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 6px 6px 0 0;
  border-bottom: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition:
    background var(--transition),
    color var(--transition);
}

.tb-page-tab:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
}

.tb-page-tab--active {
  background: #fff;
  color: #222;
  font-weight: 600;
  border-color: #fff;
}

.tb-page-tab__remove {
  background: none;
  border: none;
  margin-left: 0.25rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.1rem;
  transition: color var(--transition);
}

.tb-page-tab__remove:hover {
  color: #ff6666;
}

.tb-preview-wrap {
  background: #fff;
  border-radius: 0 4px 4px 4px;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  width: 400px;
  /* height is set by JS to maintain A4 ratio */
}

.tb-preview-wrap canvas {
  display: block;
}

.tb-layout-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
}

/* ── Export bar ── */

.tb-export-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.tb-filename-ext {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-left: -0.5rem;
}

.tb-export-mode {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
}

/* ── Buttons ── */

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition);
  white-space: nowrap;
  user-select: none;
}

.tb-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

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

.tb-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a0800;
  font-weight: 600;
}

.tb-btn--primary:hover:not(:disabled) {
  background: #f0b860;
  border-color: #f0b860;
}

.tb-btn--mode {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0;
}

.tb-mode-group .tb-btn--mode:first-child {
  border-radius: 7px 0 0 7px;
}

.tb-mode-group .tb-btn--mode:last-child {
  border-radius: 0 7px 7px 0;
  margin-left: -1px;
}

.tb-btn--mode.tb-btn--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a0800;
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.tb-btn--icon {
  padding: 0.25rem 0.6rem;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 6px;
}

/* ── Form controls ── */

.tb-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.tb-number-input {
  width: 5rem;
  padding: 0.3rem 0.5rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text);
  text-align: right;
}

.tb-number-input--sm {
  width: 3.5rem;
}

.tb-number-input:focus {
  outline: none;
  border-color: var(--accent);
}

.tb-text-input {
  padding: 0.35rem 0.6rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text);
  width: 9rem;
}

.tb-text-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Toast notifications ── */

.tb-toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.tb-toast {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.4;
  max-width: 340px;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
  pointer-events: auto;
}

.tb-toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.tb-toast--info {
  background: rgba(30, 30, 50, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.tb-toast--error {
  background: rgba(80, 10, 10, 0.97);
  border: 1px solid rgba(255, 80, 80, 0.4);
  color: #ffaaaa;
}

/* ── Responsive ── */

@media (max-width: 860px) {
  .tb-workspace {
    flex-direction: column;
  }

  .tb-sidebar {
    flex: none;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .tb-preview-panel {
    flex: none;
    width: 100%;
  }

  .tb-preview-wrap {
    width: 100%;
  }
}
