@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  font-family:
    "Plus Jakarta Sans",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei",
    sans-serif;
  
  /* Modern Slate Color Palette (Water Theme) */
  --bg-gradient-start: #f8fafc;
  --bg-gradient-end: #f1f5f9;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 211, 0.08);
  
  --secondary: #0d9488;
  --secondary-light: rgba(13, 148, 136, 0.08);
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-light: rgba(226, 232, 240, 0.8);
  --card-bg: rgba(255, 255, 255, 0.95);
  
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 20px;
  
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px 0 rgba(0, 0, 0, 0.03);
  --shadow-md: 0 10px 15px -3px rgba(15, 23, 42, 0.04), 0 4px 6px -2px rgba(15, 23, 42, 0.02);
  --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.06), 0 10px 10px -5px rgba(15, 23, 42, 0.02);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input {
  font: inherit;
}

/* Page Wrapper & Layout */
.page {
  min-height: 100vh;
  width: 100%;
  max-width: 640px; /* Perfect smartphone layout container */
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(30px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header & Brand styling */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

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

.logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(191, 219, 254, 0.5);
}

.icon-water {
  filter: drop-shadow(0 2px 4px rgba(37, 99, 235, 0.15));
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

h1 {
  margin: 0;
  color: var(--text-main);
  font-size: 20px;
  line-height: 1.2;
  font-weight: 800;
}

/* Modern Pill Refresh Button */
.refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 30px;
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
}

.refresh:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.refresh:active {
  transform: scale(0.96);
  background: #f1f5f9;
}

.refresh:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.refresh:disabled .icon-refresh {
  animation: spin 1.2s linear infinite;
}

.icon-refresh {
  transition: transform 0.3s ease;
}

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

/* Balance Summary Cards */
.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.balance-card {
  position: relative;
  min-width: 0;
  padding: 16px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.balance-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(203, 213, 225, 0.8);
}

.balance-card:active {
  transform: scale(0.98);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.account-1 .card-indicator {
  background: var(--primary);
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.6);
}

.account-2 .card-indicator {
  background: var(--secondary);
  box-shadow: 0 0 8px rgba(13, 148, 136, 0.6);
}

.balance-card span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.balance-value {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.currency {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
}

.balance-card strong {
  display: block;
  color: var(--text-main);
  font-size: clamp(20px, 6vw, 24px); /* Dynamic, never breaks */
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.time-meta {
  grid-column: 1 / -1;
  display: grid;
  gap: 4px;
}

.updated-at,
.checked-at {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  opacity: 0.8;
}

.checked-at {
  color: #475569;
  opacity: 0.95;
}

/* State message (Alert Banner) */
.state {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  color: var(--text-muted);
}

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

.state .spinner {
  animation: spin 1s linear infinite;
  color: var(--primary);
}

.state.is-error {
  border-color: rgba(254, 226, 226, 0.9);
  color: #991b1b;
  background: #fef2f2;
}

.state.is-error .state-icon {
  color: #ef4444;
}

/* Chart Container Card */
.chart-section {
  padding: 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.chart-title svg {
  color: var(--text-muted);
}

.chart {
  width: 100%;
  height: 38vh;
  min-height: 280px;
  max-height: 420px;
}

/* Detail Card & Placeholders */
.details-container {
  margin-top: 2px;
}

.details-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  border: 1px dashed rgba(203, 213, 225, 0.8);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.4);
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
}

.details-placeholder svg {
  opacity: 0.5;
  color: var(--text-muted);
}

.details-placeholder p {
  margin: 0;
}

.details {
  padding: 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.details-title {
  margin: 0 0 4px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.details-title svg {
  color: var(--primary);
}

.details-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid #f1f5f9;
}

.details-row span {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.details-row strong {
  color: var(--text-main);
  font-weight: 700;
  font-size: 13px;
  text-align: right;
}

[hidden] {
  display: none !important;
}

/* Desktop and Tablet Adaptions */
@media (min-width: 640px) {
  .page {
    padding: 32px 24px;
  }
  
  h1 {
    font-size: 22px;
  }
  
  .balance-card {
    padding: 20px 18px;
  }
  
  .chart {
    height: 320px;
  }
}
