/* ==========================================================================
   Bitcoin Signer - Compact Desktop Application Theme
   Inspired by Electrum Wallet & Desktop Password Managers (KeePassXC / 1Password)
   High Information Density, Zero-Scroll Viewport Layout
   ========================================================================== */

:root {
  --bg-app: #12151b;
  --bg-panel: #181d26;
  --bg-input: #101319;
  --bg-hover: #1f2532;
  --bg-selected: #242d3d;
  --bg-selected-border: #f7931a;

  --border-subtle: #242b38;
  --border-medium: #30394a;
  --border-focus: #f7931a;

  --accent-btc: #f7931a;
  --accent-btc-hover: #ffa83b;
  --accent-btc-subtle: rgba(247, 147, 26, 0.12);

  --accent-green: #10b981;
  --accent-green-subtle: rgba(16, 185, 129, 0.12);

  --accent-red: #ef4444;
  --accent-red-subtle: rgba(239, 68, 68, 0.12);

  --text-main: #e2e8f0;
  --text-dim: #94a3b8;
  --text-muted: #64748b;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden; /* Strict zero-scrolling for desktop app feel */
}

body.theme-desktop {
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.4;
  background-color: var(--bg-app);
  color: var(--text-main);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* Main Desktop Shell */
.desktop-app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   App Toolbar (Top Menu / Action Bar, height 34px)
   -------------------------------------------------------------------------- */
.app-toolbar {
  height: 34px;
  min-height: 34px;
  background-color: #151921;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  flex-shrink: 0;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 7px;
}

.app-icon {
  flex-shrink: 0;
}

.app-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 2px;
}

.status-indicator.unlocked {
  background-color: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
}

.status-indicator.locked {
  background-color: var(--accent-red);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.format-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
}

.format-label {
  font-size: 11px;
  color: var(--text-muted);
}

.segmented-control {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 1px;
}

.segment-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.segment-btn:hover {
  color: #fff;
}

.segment-btn.active {
  background: var(--accent-btc);
  color: #000;
  font-weight: 600;
}

.toolbar-divider {
  width: 1px;
  height: 16px;
  background-color: var(--border-subtle);
  margin: 0 2px;
}

/* Consistent Tool Buttons with Exact Vertical Alignment */
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  color: var(--text-main);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  vertical-align: middle;
  cursor: pointer;
  transition: all 0.12s ease;
}

.tool-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  color: #fff;
}

.tool-btn.text-danger {
  color: #f87171;
}

.tool-btn.text-danger:hover {
  background: var(--accent-red-subtle);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fff;
}

/* --------------------------------------------------------------------------
   Main Viewport
   -------------------------------------------------------------------------- */
.main-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Setup & Unlock Panels */
.view-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-app);
  padding: 20px;
}

.desktop-dialog {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.dialog-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.dialog-desc {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 14px;
  line-height: 1.4;
}

.dialog-form .form-row {
  margin-bottom: 10px;
}

.dialog-form label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.dialog-form input[type="text"],
.dialog-form input[type="password"] {
  width: 100%;
  height: 28px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12px;
  padding: 0 8px;
  outline: none;
  transition: border-color 0.15s ease;
}

.dialog-form input[type="text"]:focus,
.dialog-form input[type="password"]:focus {
  border-color: var(--border-focus);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap input {
  padding-right: 28px;
}

.btn-toggle-pass {
  position: absolute;
  right: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}

/* Password Strength Meter - Fixed Granular Progress */
.strength-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 10px;
}

.strength-track {
  flex: 1;
  height: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 2px;
  overflow: hidden;
  display: flex;
}

.strength-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: #64748b;
  transition: width 0.15s ease, background-color 0.15s ease;
}

.strength-caption {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 75px;
  text-align: right;
}

.dialog-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.btn-desktop {
  height: 26px;
  padding: 0 12px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s ease;
}

.btn-desktop.btn-primary {
  background: var(--accent-btc);
  color: #000;
  font-weight: 600;
}

.btn-desktop.btn-primary:hover {
  background: var(--accent-btc-hover);
}

.btn-desktop.btn-subtle {
  background: var(--bg-input);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn-desktop.btn-subtle:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  color: #fff;
}

.btn-desktop.btn-danger {
  background: var(--accent-red);
  color: #fff;
  font-weight: 600;
}

.error-strip {
  background: var(--accent-red-subtle);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  margin-top: 6px;
}

/* --------------------------------------------------------------------------
   Workspace Panel (Zero-Gap, Maximum Vertical Space Utilization)
   -------------------------------------------------------------------------- */
.workspace-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  gap: 0;
  overflow: hidden;
  height: calc(100vh - 34px - 22px); /* Minus toolbar & status bar */
}

/* The 3 Vertical Workspace Sections */
.workspace-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
}

.workspace-section:last-child {
  border-bottom: none;
}

/* 1. Identities Table Section (Top) */
.table-section {
  flex: 1.15;
  min-height: 85px;
}

.desktop-table-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--bg-input);
}

/* Custom Thin Scrollbar */
.desktop-table-container::-webkit-scrollbar,
.desktop-textarea::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
.desktop-table-container::-webkit-scrollbar-thumb,
.desktop-textarea::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 3px;
}
.desktop-table-container::-webkit-scrollbar-track,
.desktop-textarea::-webkit-scrollbar-track {
  background: transparent;
}

.desktop-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  text-align: left;
}

.desktop-table thead {
  position: sticky;
  top: 0;
  background-color: #171c25;
  border-bottom: 1px solid var(--border-subtle);
  z-index: 2;
}

.desktop-table th {
  padding: 4px 6px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-right: 1px solid var(--border-subtle);
  user-select: none;
}

.desktop-table th:last-child {
  border-right: none;
}

/* Sortable column headers */
.desktop-table th.sortable {
  cursor: pointer;
  transition: background-color 0.1s ease, color 0.1s ease;
}

.desktop-table th.sortable:hover {
  background-color: #1f2533;
  color: #fff;
}

.sort-icon {
  display: inline-block;
  margin-left: 3px;
  font-size: 8px;
  color: var(--accent-btc);
}

/* Header Add (+) Button */
.col-active {
  width: 24px;
  text-align: center;
  padding: 2px !important;
}

.header-add-btn {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1e2430;
  border: 1px solid var(--border-subtle);
  border-radius: 2px;
  color: var(--accent-btc);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: all 0.1s ease;
}

.header-add-btn:hover {
  background: var(--accent-btc);
  color: #000;
  border-color: var(--accent-btc);
}

.col-name {
  width: 28%;
}

.col-address {
  width: 54%;
}

.col-type {
  width: 18%;
  text-align: right;
}

.desktop-table tbody tr {
  height: 25px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: background-color 0.08s ease;
}

.desktop-table tbody tr:hover {
  background-color: var(--bg-hover);
}

/* Selected Active Row */
.desktop-table tbody tr.selected-row {
  background-color: var(--bg-selected);
  color: #fff;
}

.desktop-table td {
  padding: 3px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 1px solid rgba(255, 255, 255, 0.03);
}

.desktop-table td:last-child {
  border-right: none;
  text-align: right;
}

.active-indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-btc);
  box-shadow: 0 0 5px var(--accent-btc);
  margin: 0 auto;
}

.nickname-display {
  font-weight: 500;
}

.selected-row .nickname-display {
  color: #fff;
  font-weight: 600;
}

/* Inline Rename Input */
.inline-rename-input {
  width: 100%;
  height: 20px;
  background: var(--bg-input);
  border: 1px solid var(--accent-btc);
  border-radius: 2px;
  color: #fff;
  font-family: inherit;
  font-size: 11.5px;
  padding: 0 4px;
  outline: none;
}

.address-display {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #7dd3fc;
}

.type-pill {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  text-transform: uppercase;
}

.type-pill.segwit {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
}

.type-pill.legacy {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

/* 2. Message to Sign Section (Middle) */
.input-section {
  flex: 1;
  min-height: 75px;
}

.input-box-container {
  flex: 1;
  height: 100%;
  position: relative;
  display: flex;
}

.input-action-badges {
  position: absolute;
  top: 6px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  z-index: 2;
}

.action-badge-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  background: #171c26;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  opacity: 0.85;
  transition: all 0.12s ease;
  user-select: none;
}

.action-badge-btn:hover {
  opacity: 1;
  background: var(--bg-hover);
  border-color: var(--accent-btc);
  color: #fff;
}

.input-section .desktop-textarea {
  padding-right: 120px; /* Leave room for Paste and Clear buttons */
}

/* 3. Output Signature Section (Bottom) */
.output-section {
  flex: 1;
  min-height: 75px;
}

.output-section .desktop-textarea {
  padding-right: 65px; /* Leave room for Copy badge */
}

.desktop-textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  background: var(--bg-input);
  border: none;
  padding: 8px 10px;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.45;
  resize: none;
  outline: none;
}

.desktop-textarea::placeholder {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 11px;
}

.desktop-textarea:focus {
  background-color: #0d1015;
}

/* Clickable Output Box Container with Copy Icon */
.output-box-container {
  flex: 1;
  height: 100%;
  position: relative;
  display: flex;
  cursor: pointer;
  background: var(--bg-input);
  transition: all 0.15s ease;
}

.output-box-container:hover {
  background: #11141b;
}

.output-box-container:hover .output-copy-badge {
  opacity: 1;
  border-color: var(--accent-btc);
  color: var(--accent-btc);
}

.output-box-container.copied-flash {
  box-shadow: inset 0 0 0 1px var(--accent-green);
  background-color: rgba(16, 185, 129, 0.05);
}

.output-textarea {
  cursor: pointer !important;
  color: #38bdf8;
  word-break: break-all;
}

.output-copy-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: #171c26;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0.85;
  transition: all 0.12s ease;
  user-select: none;
}

.output-copy-badge.copied {
  background: var(--accent-green);
  color: #000;
  border-color: var(--accent-green);
  opacity: 1;
}

/* --------------------------------------------------------------------------
   App Status Bar (Bottom, height 22px)
   -------------------------------------------------------------------------- */
.app-statusbar {
  height: 22px;
  min-height: 22px;
  background-color: #12151b;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-size: 10.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}

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

.status-segment {
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-green);
}

.status-dim {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

/* --------------------------------------------------------------------------
   Compact Desktop Modals
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-dialog {
  width: 90%;
  max-width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.modal-dialog-sm {
  max-width: 290px;
}

.modal-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 6px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.modal-close-btn:hover {
  color: #fff;
}

.dialog-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 10px;
}

.dialog-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 0;
  cursor: pointer;
}

.dialog-tab.active {
  color: var(--accent-btc);
  border-bottom-color: var(--accent-btc);
  font-weight: 600;
}

.inline-segment {
  width: 100%;
}
.inline-segment .segment-btn {
  flex: 1;
  text-align: center;
}

.mono-input {
  font-family: var(--font-mono);
  font-size: 11px !important;
}

.inline-copy-wrap {
  display: flex;
  gap: 4px;
}

.qr-box {
  background: #fff;
  padding: 6px;
  border-radius: var(--radius-xs);
  display: inline-block;
  margin: 6px auto;
}

.qr-image {
  display: block;
  width: 160px;
  height: 160px;
}

.mono-text-sm {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  word-break: break-all;
}

.text-selectable {
  user-select: text;
}

.text-danger {
  color: var(--accent-red) !important;
}

.text-danger-soft {
  color: #fca5a5;
  font-size: 10.5px;
}

.justify-center {
  justify-content: center !important;
}

.mt-2 { margin-top: 6px; }
.mt-3 { margin-top: 10px; }

/* Desktop Toast */
.desktop-toast {
  position: fixed;
  bottom: 28px;
  right: 12px;
  background: #1e2532;
  border: 1px solid var(--accent-btc);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* Utility Hidden */
.hidden {
  display: none !important;
}
