* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
}

/* ── App shell ── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px 0;
}

/* ── Header ── */
.app-header {
  text-align: center;
  color: white;
  padding: 8px 0 10px;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.6rem;
  text-shadow: 1px 1px 3px rgba(0,0,0,.3);
}

.app-header p {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 2px;
}

/* ── Tab nav ── */
.tab-nav {
  display: flex;
  gap: 4px;
  background: white;
  border-radius: 10px;
  padding: 6px;
  margin-bottom: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,.12);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 9px 12px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  transition: all 0.2s;
  background: transparent;
  color: #718096;
}

.tab-btn:hover:not(:disabled) {
  background: #f0f0ff;
  color: #667eea;
}

.tab-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(102,126,234,.4);
}

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

/* ── Tab panels ── */
.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* ── Generic panel card ── */
.panel-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 6px 20px rgba(0,0,0,.08);
  margin-bottom: 12px;
}

.panel-card h2 {
  margin-bottom: 20px;
  color: #4a5568;
  font-size: 1.3rem;
}

/* ── Upload panel ── */
#panel-upload {
  align-items: center;
  justify-content: center;
}

#panel-upload .panel-card {
  width: 100%;
  max-width: 560px;
}

.file-upload {
  position: relative;
  display: inline-block;
}

.file-upload input[type="file"] {
  position: absolute;
  left: -9999px;
}

.file-label {
  display: inline-block;
  padding: 14px 28px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
}

.file-label:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102,126,234,.4);
}

.file-info {
  margin-top: 15px;
  padding: 12px;
  background: #f7fafc;
  border-radius: 8px;
  border-left: 4px solid #667eea;
  font-size: 0.9rem;
}

/* ── Transactions panel (drag-drop) ── */
#panel-transactions {
  overflow: hidden;
}

.drag-drop-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 12px;
  height: 100%;
  min-height: 0;
}

.transactions-panel,
.categories-panel {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.08);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.transactions-panel h3,
.categories-panel h3 {
  margin-bottom: 12px;
  color: #4a5568;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.categories-panel h3 {
  text-align: center;
}

/* ── Keywords panel ── */
#panel-keywords {
  overflow-y: auto;
}

/* ── Preview panel ── */
#panel-preview {
  overflow-y: auto;
}

/* ── Filter controls ── */
.filter-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #f7fafc;
  border-radius: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.filter-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #4a5568;
  cursor: pointer;
  user-select: none;
}

.filter-controls input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #667eea;
}

.filter-controls .filter-label {
  font-weight: 600;
  color: #2d3748;
}

/* ── Table ── */
.table-container {
  overflow-x: auto;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  flex: 1;
  min-height: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.88rem;
}

th {
  background: #f7fafc;
  font-weight: 600;
  color: #4a5568;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:hover { background: #f7fafc; }

/* ── Drag rows ── */
.transaction-row,
.raw-transaction-row {
  cursor: grab;
  transition: all 0.2s;
}
.transaction-row:active,
.raw-transaction-row:active { cursor: grabbing; }
.transaction-row.dragging,
.raw-transaction-row.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
  box-shadow: 0 5px 15px rgba(0,0,0,.3);
}
.transaction-row.hidden,
.raw-transaction-row.hidden { display: none; }

/* ── Status badges ── */
.status-uncategorized { color: #e53e3e; font-weight: bold; }
.status-categorized   { color: #38a169; font-weight: bold; }

/* ── Row highlights ── */
.uncategorized-highlight { background: #fed7d7 !important; }
.manually-categorized    { background: #c6f6d5 !important; }

/* ── Compact drop zones ── */
.compact-category-card {
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  transition: all 0.2s;
  margin-bottom: 8px;
}
.compact-category-card:hover { border-color: #667eea; }
.compact-category-card.drag-over {
  border-color: #48bb78;
  background: #f0fff4;
  transform: scale(1.02);
}
.compact-category-name {
  font-weight: 600;
  color: #2d3748;
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.compact-drop-zone {
  min-height: 36px;
  border: 2px dashed #cbd5e0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0aec0;
  font-size: 0.78rem;
  transition: all 0.2s;
}
.compact-drop-zone.drag-over {
  border-color: #48bb78;
  background: #f0fff4;
  color: #38a169;
}

/* ── Category cards (keywords tab) ── */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.category-card {
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  background: #f8fafc;
  transition: all 0.2s;
}
.category-card:hover { border-color: #667eea; }
.category-card.drag-over {
  border-color: #48bb78;
  background: #f0fff4;
  transform: scale(1.02);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.category-name { font-weight: 600; color: #2d3748; font-size: 1rem; }

.delete-category {
  background: #e53e3e;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.75rem;
}

.add-category {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.add-category input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.95rem;
}
.add-category button,
.export-btn {
  padding: 10px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}
.add-category button:hover,
.export-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102,126,234,.4);
}

.keywords-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.keywords-list { display: flex; flex-wrap: wrap; gap: 6px; }

.keyword-tag {
  background: #667eea;
  color: white;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 4px;
}
.keyword-tag .remove { cursor: pointer; font-weight: bold; }

.category-drop-zone {
  min-height: 50px;
  border: 2px dashed #cbd5e0;
  border-radius: 7px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0aec0;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.category-drop-zone.drag-over {
  border-color: #48bb78;
  background: #f0fff4;
  color: #38a169;
}

/* ── Ignore keyword tags ── */
.ignore-keyword-tag {
  background: #e53e3e;
  color: white;
  padding: 5px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.ignore-keyword-tag .remove {
  cursor: pointer;
  font-weight: bold;
  padding: 1px 4px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
}
.ignore-keyword-tag .remove:hover { background: rgba(255,255,255,.35); }

/* ── Stats ── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px;
  border-radius: 10px;
  text-align: center;
}
.stat-value { font-size: 1.6rem; font-weight: bold; margin-bottom: 4px; }
.stat-label { font-size: 0.85rem; opacity: 0.9; }

/* ── Manual category select ── */
.manual-category-select {
  padding: 3px 6px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  font-size: 0.8rem;
  background: white;
  cursor: pointer;
}

/* ── Export btn (preview tab) ── */
.export-btn { font-size: 0.95rem; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .drag-drop-layout {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .categories-panel { max-height: 300px; }
}

@media (max-width: 600px) {
  .app-shell { padding: 8px 8px 0; }
  .tab-btn { font-size: 0.75rem; padding: 7px 6px; }
  .categories-grid { grid-template-columns: 1fr; }
  .add-category { flex-direction: column; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
