/* Stand Quest — Mobile-first PWA styling */

:root {
  --bg: #0f1419;
  --bg-elev: #1a2129;
  --bg-elev-2: #232c36;
  --border: #2d3744;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #6b7480;
  --accent: #10b981;
  --accent-hover: #14d597;
  --accent-dim: rgba(16, 185, 129, 0.15);
  --danger: #f87171;
  --danger-hover: #fca5a5;
  --warning: #fbbf24;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top: env(safe-area-inset-top, 0);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: calc(64px + var(--safe-bottom));
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 22px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-elev);
  color: var(--text);
}

.date-line {
  padding: 0 20px 24px;
  color: var(--text-dim);
  font-size: 14px;
  text-transform: capitalize;
}

/* ---------- Views ---------- */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
}

.view-active {
  display: flex;
}

.state-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 32px;
}

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

/* ---------- Big button ---------- */
.big-btn {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
  color: white;
  box-shadow: var(--shadow);
  transition: transform 0.1s, box-shadow 0.2s;
}

.big-btn:active {
  transform: scale(0.96);
}

.big-btn-start {
  background: linear-gradient(135deg, #10b981, #059669);
}

.big-btn-stop {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.big-btn-icon {
  font-size: 56px;
  line-height: 1;
}

.big-btn-label {
  font-size: 20px;
  letter-spacing: 0.02em;
}

/* ---------- Stats ---------- */
.stats {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

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

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- Active timer ---------- */
.timer-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 280px;
  height: 280px;
}

.timer-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--accent-dim);
  animation: pulse 2s ease-in-out infinite;
}

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

.timer-display {
  position: relative;
  font-size: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--text);
  z-index: 1;
}

.timer-sub {
  position: relative;
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-dim);
  z-index: 1;
}

/* ---------- Bottom tabs ---------- */
.bottom-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
  max-width: 480px;
  margin: 0 auto;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0;
  color: var(--text-muted);
  font-size: 11px;
  transition: color 0.15s;
}

.tab-icon {
  font-size: 22px;
}

.tab-active {
  color: var(--accent);
}

/* ---------- Footer ---------- */
.app-footer {
  position: fixed;
  bottom: calc(64px + var(--safe-bottom) + 4px);
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 5;
}

/* ---------- Log view ---------- */
#log-content {
  padding: 0 20px 20px;
}

.log-section {
  margin-bottom: 28px;
}

.log-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  padding: 0 4px;
}

.log-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.log-section-total {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.session-item:active {
  background: var(--bg-elev-2);
}

.session-time {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.session-duration {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Week bar chart */
.week-chart {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 120px;
  padding: 12px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.week-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 4px;
}

.week-bar-fill {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}

.week-bar-fill.empty {
  background: var(--border);
}

.week-bar-fill.today {
  background: var(--accent-hover);
  box-shadow: 0 0 12px var(--accent-dim);
}

.week-bar-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

.week-bar-value {
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.month-group {
  margin-bottom: 16px;
}

.month-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-dim);
}

.month-header-chevron {
  transition: transform 0.2s;
  color: var(--text-muted);
}

.month-group.expanded .month-header-chevron {
  transform: rotate(90deg);
}

.month-sessions {
  display: none;
}

.month-group.expanded .month-sessions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  animation: fade-in 0.2s;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: var(--safe-bottom);
  animation: slide-up 0.25s ease-out;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  gap: 12px;
}

.setting-row span {
  font-size: 14px;
  color: var(--text);
}

.setting-row input {
  width: 100px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  text-align: right;
  font-family: inherit;
}

.setting-row input[type="datetime-local"] {
  width: auto;
  flex: 1;
}

.primary-btn, .secondary-btn, .secondary-btn-label, .danger-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

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

.secondary-btn:hover, .secondary-btn-label:hover {
  background: var(--bg-elev-2);
}

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

.danger-btn:hover, .danger-btn:active {
  background: rgba(248, 113, 113, 0.1);
}

.modal-meta {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 200;
  animation: toast-in 0.2s ease-out;
  max-width: 90vw;
  text-align: center;
}

.toast.hidden {
  display: none;
}

@keyframes toast-in {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- Responsive (desktop preview) ---------- */
@media (min-width: 600px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    min-height: 100vh;
  }
}
