:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #f1f2f4;
    --text-muted: #9aa1ac;
    --border: #2b2f37;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.app-header {
  text-align: center;
  margin-bottom: 20px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

input,
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--text);
  width: 100%;
}

input:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
}

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

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

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 100%;
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary-header label {
  font-size: 1rem;
  color: var(--text);
  font-weight: 600;
}

.summary-header input {
  width: auto;
}

.summary-stats {
  display: flex;
  gap: 12px;
}

.stat {
  flex: 1;
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.category-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.category-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.list-card h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.day-group-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 10px 0 2px;
}

.invoice-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
}

.invoice-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.invoice-info {
  flex: 1;
  min-width: 0;
}

.invoice-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.invoice-amount {
  font-weight: 700;
  white-space: nowrap;
}

.invoice-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--text-muted);
}

.icon-btn:hover {
  background: var(--border);
}

.icon-btn.delete:hover {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 20px 0;
}

.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 24px;
}

.field-amount {
  flex: 2;
}

.field-currency {
  flex: 1;
}

.rates-status {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.rates-status.warn {
  color: var(--danger);
}

.invoice-amount {
  text-align: left;
}

.invoice-amount .sar-equivalent {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

@media (max-width: 420px) {
  .form-row {
    flex-direction: column;
    gap: 12px;
  }
  .summary-header {
    flex-direction: column;
    align-items: stretch;
  }
}
