/* ===================== Reset & Base ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface2:   #21262d;
  --border:     #30363d;
  --accent:     #00e5a0;
  --accent-dim: #00b37d;
  --text:       #e6edf3;
  --text-muted: #8b949e;
  --danger:     #f85149;
  --warning:    #e3b341;
  --info:       #58a6ff;
  --radius:     12px;
  --shadow:     0 4px 24px rgba(0,0,0,.4);
  --nav-h:      64px;
  --header-h:   56px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===================== Screen / Section logic ===================== */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; height: 100dvh; }

.section { display: none; flex: 1; overflow-y: auto; padding: 16px 16px calc(16px + var(--nav-h)); }
.section.active { display: block; }

/* ===================== Login ===================== */
#login-screen.active {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 32px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.login-logo h1 { font-size: 22px; font-weight: 700; }
.login-logo p  { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--bg); width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }

.btn-danger  { background: rgba(248,81,73,.15); color: var(--danger); border: 1px solid rgba(248,81,73,.3); }
.btn-danger:hover { background: rgba(248,81,73,.25); }

.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 6px; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 6px; font-size: 18px; }
.btn-icon:hover { color: var(--text); }

/* ===================== App Header ===================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.app-header h1 { font-size: 17px; font-weight: 700; color: var(--accent); }

/* ===================== Bottom Nav ===================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--accent); }
.nav-btn:hover  { color: var(--text); }

.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 500; }

/* ===================== Filter Tabs ===================== */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.filter-btn {
  flex: 1;
  background: none;
  border: none;
  border-radius: 7px;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active { background: var(--accent); color: var(--bg); }

/* ===================== Cards ===================== */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.card.green::before  { background: var(--accent); }
.card.red::before    { background: var(--danger); }
.card.blue::before   { background: var(--info); }
.card.orange::before { background: var(--warning); }

.card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.card-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.card.green .card-value  { color: var(--accent); }
.card.red   .card-value  { color: var(--danger); }
.card.blue  .card-value  { color: var(--info); }
.card.orange .card-value { color: var(--warning); }

.card-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-wide {
  grid-column: 1 / -1;
}

/* Stats row */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

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

.stat-pill .val { font-size: 20px; font-weight: 700; }
.stat-pill .lbl { font-size: 11px; color: var(--text-muted); }

/* ===================== Section Title ===================== */
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

/* ===================== Upload ===================== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 16px;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(0, 229, 160, .06);
}

.drop-icon { font-size: 40px; margin-bottom: 12px; }
.drop-text { color: var(--text-muted); font-size: 14px; }
.drop-text strong { color: var(--accent); display: block; margin-bottom: 4px; font-size: 16px; }

/* Preview card */
.preview-card {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.preview-card h3 { font-size: 14px; margin-bottom: 16px; color: var(--accent); }

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.preview-grid .form-group { margin-bottom: 0; }

.preview-actions { display: flex; gap: 10px; }
.preview-actions .btn { flex: 1; }

/* ===================== History ===================== */
.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab-btn {
  padding: 8px 16px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.tab-btn.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead { background: var(--surface2); }
thead th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr { border-top: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 12px; white-space: nowrap; }

.text-green  { color: var(--accent); font-weight: 600; }
.text-red    { color: var(--danger); font-weight: 600; }
.text-blue   { color: var(--info); font-weight: 600; }
.text-muted  { color: var(--text-muted); }

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

.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===================== Add Section ===================== */
.add-tabs { display: flex; gap: 8px; margin-bottom: 24px; }

.add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===================== Settings ===================== */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text-muted); }

/* ===================== Toast ===================== */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: all .25s;
  pointer-events: auto;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error   { border-color: var(--danger); color: var(--danger); }
.toast.info    { border-color: var(--info); color: var(--info); }

/* ===================== Spinner / Loading ===================== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,17,23,.7);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.loading-box .spinner { width: 28px; height: 28px; border-width: 3px; color: var(--accent); }
.loading-box p { font-size: 14px; color: var(--text-muted); }

/* ===================== Utilities ===================== */
.hidden  { display: none !important; }
.mt-8    { margin-top: 8px; }
.mt-16   { margin-top: 16px; }
.mb-16   { margin-bottom: 16px; }
.text-center { text-align: center; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success-msg { color: var(--accent); font-size: 13px; margin-top: 8px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(0,229,160,.15);
  color: var(--accent);
}

/* ===================== Week Detail Modal ===================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
}
.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .75);
}

.modal-sheet {
  position: relative;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 calc(24px + env(safe-area-inset-bottom, 0));
  animation: slideUp .25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  z-index: 2;
}

.modal-header h3 { font-size: 15px; font-weight: 700; }

.modal-body { padding: 16px; }

.modal-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin: 20px 0 10px;
}

.modal-body .cards-grid { margin-bottom: 0; }

/* ===================== Clickable table rows ===================== */
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface2); }

/* ===================== Responsive ===================== */
@media (min-width: 600px) {
  .cards-grid { grid-template-columns: 1fr 1fr 1fr; }
  .section { max-width: 700px; margin: 0 auto; }
  .app-header { max-width: 700px; margin: 0 auto; width: 100%; position: relative; }
  .bottom-nav { max-width: 700px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
  .modal-sheet { max-width: 700px; margin: 0 auto; border-radius: 20px 20px 0 0; }
}
