/* ===== CSS Variables ===== */
:root {
  --primary: #6c63ff;
  --primary-light: #ede9ff;
  --accent: #ff6584;
  --accent-light: #ffe9ee;
  --boy: #4fc3f7;
  --boy-light: #e1f5fe;
  --girl: #f48fb1;
  --girl-light: #fce4ec;
  --text: #2d2d3a;
  --text-muted: #7a7a9d;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --border: #e8e8f0;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(108,99,255,0.08);
}

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

body {
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
header {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 12px rgba(108,99,255,0.3);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}
.logo { font-size: 28px; }
header h1 { font-size: 20px; font-weight: 700; letter-spacing: 0.04em; }

/* Main */
main {
  max-width: 960px;
  margin: 32px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Card */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

/* Form Row */
.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.form-row input, .form-row select {
  flex: 1;
  min-width: 140px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: #fafafd;
  outline: none;
  transition: border-color 0.2s;
}
.form-row input:focus, .form-row select:focus {
  border-color: var(--primary);
  background: white;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(108,99,255,0.3);
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(108,99,255,0.4); }
.btn-accent {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(255,101,132,0.3);
}
.btn-accent:hover { box-shadow: 0 4px 16px rgba(255,101,132,0.4); }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-danger {
  background: transparent;
  color: #e53935;
  border: none;
  padding: 6px 10px;
  font-size: 13px;
}
.btn-danger:hover { background: #ffebee; border-radius: 8px; }

/* Children Grid */
.children-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

/* Child Card */
.child-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.child-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
}
.child-card.boy::before { background: var(--boy); }
.child-card.girl::before { background: var(--girl); }
.child-card:hover { transform: translateY(-3px); box-shadow: 0 8px 32px rgba(108,99,255,0.14); }

.child-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.child-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.boy .child-avatar { background: var(--boy-light); }
.girl .child-avatar { background: var(--girl-light); }

.child-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.child-age {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.child-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}
.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.stat-change {
  font-size: 11px;
  color: #43a047;
  font-weight: 600;
}

.child-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.view-btn {
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}
.delete-child-btn {
  font-size: 18px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}
.delete-child-btn:hover { color: #e53935; background: #ffebee; }

.no-records {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 0;
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state p { font-size: 16px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 30, 50, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
  padding: 16px;
}
.modal {
  background: white;
  border-radius: 20px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 64px rgba(30,30,50,0.18);
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body {
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Chart */
.chart-area {
  background: var(--bg);
  border-radius: 12px;
  padding: 16px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-area canvas { max-height: 188px; }

/* Records Table */
.records-table-wrap { overflow-x: auto; }
.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.records-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.records-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.records-table tr:last-child td { border-bottom: none; }
.records-table tr:hover td { background: var(--bg); }

.badge-grow { color: #43a047; font-weight: 600; font-size: 13px; }
.badge-first { color: var(--text-muted); font-size: 12px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.3s cubic-bezier(.175,.885,.32,1.275);
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== Header Right: Sync Status ===== */
.header-inner { justify-content: space-between; }
header h1 { flex: 1; }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sync-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  cursor: default;
  transition: background 0.3s, color 0.3s;
}
.sync-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}
.sync-disconnected {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7);
}
.sync-disconnected .sync-dot { background: rgba(255,255,255,0.4); }

.sync-connected {
  background: rgba(67,160,71,0.2);
  color: #c8e6c9;
}
.sync-connected .sync-dot { background: #66bb6a; }

.sync-syncing {
  background: rgba(255,193,7,0.2);
  color: #fff9c4;
}
.sync-syncing .sync-dot {
  background: #ffc107;
  animation: pulse-dot 1s ease-in-out infinite;
}
.sync-error {
  background: rgba(229,57,53,0.2);
  color: #ffcdd2;
}
.sync-error .sync-dot { background: #ef5350; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.7); }
}

.btn-icon {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 18px;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.btn-icon:hover { background: rgba(255,255,255,0.28); }

/* ===== Microsoft Button ===== */
.btn-ms {
  width: 100%;
  background: #0078d4;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,120,212,0.3);
}
.btn-ms:hover { background: #106ebe; box-shadow: 0 4px 16px rgba(0,120,212,0.4); }
.btn-ms:active { transform: scale(0.98); }
.btn-ms:disabled { background: #aaa; cursor: not-allowed; box-shadow: none; }

/* ===== Settings Modal ===== */
.settings-modal { max-width: 520px; }

.settings-body {
  gap: 16px;
}

.settings-section {
  background: var(--bg);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.settings-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.settings-field input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: 'Consolas', 'Courier New', monospace;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 0.2s;
}
.settings-field input:focus { border-color: var(--primary); }
.field-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* Guide details */
.guide-details {
  background: #f0f4ff;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  border: 1px solid #dde3f5;
}
.guide-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary);
  user-select: none;
  list-style: none;
}
.guide-details summary::-webkit-details-marker { display: none; }
.guide-details summary::before { content: '▶ '; font-size: 10px; }
.guide-details[open] summary::before { content: '▼ '; }

.guide-steps {
  margin: 12px 0 4px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  line-height: 1.6;
}
.guide-steps a { color: var(--primary); }

.redirect-uri-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 4px;
}
.redirect-uri-box code {
  flex: 1;
  font-size: 11px;
  color: #555;
  word-break: break-all;
}
.btn-copy {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.btn-copy:hover { background: var(--border); }

/* Status messages */
.status-msg {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  display: none;
}
.status-msg.show { display: block; }
.status-msg.info  { background: #e3f2fd; color: #1565c0; }
.status-msg.error { background: #ffebee; color: #c62828; }
.status-msg.success { background: #e8f5e9; color: #2e7d32; }

/* Connected banner */
.connected-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #e8f5e9;
  border-radius: 12px;
  padding: 16px;
}
.connected-icon { font-size: 28px; }
.connected-name { font-size: 15px; font-weight: 700; color: #2e7d32; }
.connected-site { font-size: 12px; color: #555; margin-top: 2px; word-break: break-all; }

/* Logged-in hint */
.user-logged-in-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #e3f2fd;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #1565c0;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 600px) {
  main { margin: 16px auto; }
  .card { padding: 16px; }
  .form-row input, .form-row select { min-width: 120px; }
  .modal { max-height: 95vh; }
  .sync-label { display: none; }
}
