:root {
  --primary: #667eea;
  --primary-dark: #5a67d8;
  --secondary: #764ba2;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --success: #48bb78;
  --danger: #f56565;
  --warning: #ed8936;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 600;
}

.header-nav {
  display: flex;
  gap: 12px;
}

.header-nav a, .header-nav button {
  color: white;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.header-nav a:hover, .header-nav button:hover {
  background: rgba(255,255,255,0.25);
}

.header-nav a.active {
  background: rgba(255,255,255,0.3);
  font-weight: 600;
}

/* Container */
.container {
  max-width: 1000px;
  margin: 24px auto;
  padding: 0 24px;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  color: var(--primary-dark);
}

/* Form elements */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-light);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

/* Multi-select currencies */
.currency-select-area {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f7fafc;
  max-height: 200px;
  overflow-y: auto;
}

.currency-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  user-select: none;
}

.currency-chip:hover {
  border-color: var(--primary);
}

.currency-chip.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.currency-chip input[type="checkbox"] {
  display: none;
}

/* Buttons */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102,126,234,0.4);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #38a169;
}

.btn-danger {
  background: var(--danger);
  color: white;
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-danger:hover {
  background: #e53e3e;
}

.btn-warning {
  background: var(--warning);
  color: white;
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-warning:hover {
  background: #dd6b20;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

/* Results */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.result-item {
  background: linear-gradient(135deg, #f7fafc, #edf2f7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.result-item .currency-name {
  font-size: 0.85rem;
  color: var(--text-light);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.result-item .currency-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.result-item .currency-detail {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 6px;
}

.result-item .currency-subtotal {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--secondary);
  margin-top: 2px;
}

.result-total {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius);
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
}

.result-total .total-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.result-total .total-value.total-match {
  color: #c6f6d5;
}

.result-total .total-value.total-mismatch {
  color: #fed7d7;
}

.result-total .total-target {
  opacity: 0.8;
  font-weight: 400;
}

.result-note {
  grid-column: 1 / -1;
  text-align: center;
  padding: 10px;
  font-size: 0.85rem;
  color: var(--warning);
  font-weight: 600;
  background: #fffaf0;
  border: 1px solid #feebc8;
  border-radius: var(--radius);
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: #f7fafc;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-light);
  text-transform: uppercase;
}

.data-table tr:hover {
  background: #f7fafc;
}

.data-table input[type="number"] {
  width: 120px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.data-table input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Segments list */
.segment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: white;
  transition: box-shadow 0.2s;
}

.segment-item:hover {
  box-shadow: var(--shadow);
}

.segment-item .segment-name {
  font-weight: 600;
}

.segment-item .segment-actions {
  display: flex;
  gap: 8px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.modal-header h2 {
  color: var(--primary-dark);
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px 8px;
}

.modal-close:hover {
  color: var(--danger);
}

/* Currency list in modal */
.currency-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 6px;
}

.currency-list-item input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Add row */
.add-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.add-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Inline editing */
.inline-edit {
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-size: inherit;
}

.inline-edit:focus {
  border-color: var(--primary);
  background: white;
  outline: none;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.alert-success {
  background: #f0fff4;
  color: #276749;
  border: 1px solid #c6f6d5;
}

.alert-error {
  background: #fed7d7;
  color: #9b2c2c;
  border: 1px solid #feb2b2;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-light);
}

/* Loading */
.loading {
  text-align: center;
  padding: 20px;
  color: var(--text-light);
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
  .container { padding: 0 12px; }
  .results-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .header { flex-direction: column; gap: 12px; }
}
