/* ===== CSS VARIABLES ===== */
:root {
  --color-primary:        #4d91db;
  --color-primary-hover:  #3a7bc8;
  --color-primary-active: #2f69b0;
  --color-danger:         #e05252;
  --color-danger-hover:   #c93d3d;
  --color-secondary-bg:   #f0f2f5;
  --color-secondary-hover:#e2e5ea;
  --color-text:           #1a2533;
  --color-text-muted:     #6b7a8f;
  --color-border:         #dde1e8;
  --color-bg:             #ffffff;
  --color-bg-page:        #f5f7fa;
  --color-success:        #2d9e6b;
  --color-success-bg:     #e9f8f1;
  --color-error:          #c93d3d;
  --color-error-bg:       #fdeaea;
  --color-tab-active:     #4d91db;
  --color-header-bg:      #ffffff;
  --color-header-border:  #dde1e8;
  --shadow-sm:            0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:            0 2px 8px rgba(0,0,0,0.12);
  --radius:               6px;
  --radius-sm:            4px;
  --font:                 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-base:       14px;
  --font-size-sm:         12px;
  --transition:           0.15s ease;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
}

body {
  font-family: var(--font);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg-page);
  line-height: 1.5;
}

/* ===== APP LAYOUT ===== */
#app {
  min-width: 700px;
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: 60px; /* space for status bar */
}

/* ===== HEADER ===== */
.app-header {
  background: var(--color-header-bg);
  border-bottom: 1px solid var(--color-header-border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

/* ===== ERROR BANNER ===== */
.error-banner {
  background: var(--color-error-bg);
  border-left: 4px solid var(--color-error);
  color: var(--color-error);
  padding: 12px 24px;
  font-size: var(--font-size-base);
}

/* ===== TABS ===== */
.tabs-bar {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  display: flex;
  gap: 0;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 14px 20px 11px;
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  outline: none;
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--color-text);
}

.tab-btn.active {
  color: var(--color-tab-active);
  border-bottom-color: var(--color-tab-active);
}

/* ===== TAB PANELS ===== */
.tab-panel {
  padding: 20px 24px;
}

.tab-panel.hidden {
  display: none;
}

/* ===== PANEL TOOLBAR ===== */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-footer {
  margin-top: 12px;
}

/* ===== LOADING INDICATOR ===== */
.loading-indicator {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

.loading-indicator.hidden {
  display: none;
}

/* ===== TABLE ===== */
.table-wrapper {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  background: var(--color-secondary-bg);
}

thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
}

tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8f9fc;
}

tbody td {
  padding: 8px 12px;
  vertical-align: middle;
}

/* Column widths for mapping table */
#mapping-table th:nth-child(1),
#mapping-table td:nth-child(1) { width: 160px; }
#mapping-table th:nth-child(2),
#mapping-table td:nth-child(2) { width: auto; min-width: 220px; }
#mapping-table th:nth-child(3),
#mapping-table td:nth-child(3) { width: auto; min-width: 200px; }
#mapping-table th:nth-child(4),
#mapping-table td:nth-child(4) { width: 80px; text-align: center; }
#mapping-table th:nth-child(5),
#mapping-table td:nth-child(5) { width: 48px; text-align: center; }

/* Column widths for templates table */
#templates-table th:nth-child(1),
#templates-table td:nth-child(1) { width: 120px; }
#templates-table th:nth-child(2),
#templates-table td:nth-child(2) { width: 200px; }
#templates-table th:nth-child(3),
#templates-table td:nth-child(3) { width: auto; }
#templates-table th:nth-child(4),
#templates-table td:nth-child(4) { width: 80px; text-align: center; }
#templates-table th:nth-child(5),
#templates-table td:nth-child(5) { width: 48px; text-align: center; }

.col-repeat,
.col-default,
.col-delete {
  text-align: center;
}

/* Source cell: stacked selects */
.td-source {
  display: table-cell;
}

.td-source .select-source {
  display: block;
  width: 100%;
  margin-bottom: 4px;
}

.td-source .select-sub {
  display: block;
  width: 100%;
}

.td-source .select-sub.hidden {
  display: none;
}

/* Attribute cell */
.td-attribute .select-attr {
  display: block;
  width: 100%;
}

.td-attribute .select-attr.hidden {
  display: none;
}

.attr-auto-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

/* Repeat label */
.repeat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  white-space: nowrap;
}

.repeat-label.hidden {
  display: none;
}

.repeat-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* ===== FORM INPUTS ===== */
.input,
.select {
  width: 100%;
  padding: 6px 10px;
  font-size: var(--font-size-base);
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7a8f' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.input:focus,
.select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(77, 145, 219, 0.15);
}

.input::placeholder {
  color: #adb5bd;
}

input[type="radio"].radio-default {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: var(--font-size-base);
  font-family: var(--font);
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), box-shadow var(--transition);
  outline: none;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(77, 145, 219, 0.3);
}

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

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-primary-active);
}

.btn-secondary {
  background: var(--color-secondary-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-secondary-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
  padding: 5px 10px;
  font-size: 13px;
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-hover);
}

.btn-icon {
  padding: 5px 8px;
  font-size: 14px;
  line-height: 1;
}

/* ===== SETTINGS SECTION ===== */
.settings-section {
  margin-top: 28px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.settings-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}

.settings-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px 16px;
  align-items: start;
}

.settings-label {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text);
  padding-top: 7px;
}

.settings-hint {
  grid-column: 2;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: -4px;
}

/* ===== STATUS BAR ===== */
.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 24px;
  font-size: var(--font-size-base);
  font-weight: 500;
  z-index: 1000;
  transition: opacity var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-bar.hidden {
  display: none;
}

.status-bar.status-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-top: 2px solid var(--color-success);
}

.status-bar.status-error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border-top: 2px solid var(--color-error);
}

/* ===== UTILITY ===== */
.hidden {
  display: none !important;
}

/* ===== SCROLLBAR (WebKit) ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #b0b8c4;
}
