/* ─────────────────────────────────────────────────────────────────────────────
   TOKENS
───────────────────────────────────────────────────────────────────────────── */
:root {
  --bg:           #f0f2f5;
  --surface:      #ffffff;
  --surface2:     #f7f8fa;
  --border:       #e3e6ed;
  --border-soft:  #edf0f5;
  --text:         #111827;
  --muted:        #6b7280;
  --muted-light:  #9ca3af;

  --spotify:      #1db954;
  --netflix:      #e50914;
  --mysubs:       #2563eb;

  --paid:         #16a34a;   --paid-bg:     #dcfce7;
  --pending:      #b45309;   --pending-bg:  #fef3c7;
  --late:         #dc2626;   --late-bg:     #fee2e2;
  --promised:     #7c3aed;   --promised-bg: #ede9fe;

  --radius:    10px;
  --radius-sm:  6px;
  --shadow:    0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.09);
}

/* ─────────────────────────────────────────────────────────────────────────────
   RESET & BASE
───────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ─────────────────────────────────────────────────────────────────────────────
   LOGIN SCREEN
───────────────────────────────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

#login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

#login-box .lock-icon {
  font-size: 36px;
  margin-bottom: 16px;
}

#login-box h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

#login-box p {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 24px;
}

#login-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  outline: none;
  text-align: center;
  letter-spacing: 3px;
  margin-bottom: 12px;
  transition: border-color .15s, box-shadow .15s;
}

#login-input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(147,197,253,.25);
}

#login-error {
  font-size: 12px;
  color: var(--late);
  min-height: 18px;
  margin-bottom: 12px;
}

#btn-login {
  width: 100%;
  padding: 10px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}

#btn-login:hover { opacity: .85; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

#login-box.shake { animation: shake .4s ease; }

/* ─────────────────────────────────────────────────────────────────────────────
   APP WRAPPER
───────────────────────────────────────────────────────────────────────────── */
#app {
  display: none;
  padding: 28px 16px 64px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   HEADER
───────────────────────────────────────────────────────────────────────────── */
header {
  max-width: 900px;
  margin: 0 auto 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

header h1 { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
header p  { font-size: 12px; color: var(--muted); margin-top: 2px; }

.header-actions { display: flex; gap: 8px; }

.btn-header {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: background .12s, box-shadow .12s;
}
.btn-header:hover { background: var(--surface2); box-shadow: var(--shadow-md); }
.btn-save { border-color: #c6d9ff; color: #1d4ed8; }
.btn-save:hover { background: #eff6ff; }

.autosave-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

/* ─────────────────────────────────────────────────────────────────────────────
   TABS
───────────────────────────────────────────────────────────────────────────── */
.tabs {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  border: none; background: none;
  color: var(--muted);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active-spotify { color: var(--spotify); border-bottom-color: var(--spotify); }
.tab-btn.active-netflix { color: var(--netflix); border-bottom-color: var(--netflix); }
.tab-btn.active-mysubs  { color: var(--mysubs);  border-bottom-color: var(--mysubs);  }

.tab-icon {
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
}
.spotify-icon { background: var(--spotify); color: #fff; }
.netflix-icon { background: var(--netflix); color: #fff; }
.mysubs-icon  { background: var(--mysubs);  color: #fff; }

/* ─────────────────────────────────────────────────────────────────────────────
   PANELS
───────────────────────────────────────────────────────────────────────────── */
.panel {
  display: none;
  max-width: 900px;
  margin: 0 auto;
  padding-top: 24px;
}
.panel.active { display: block; }

/* ─────────────────────────────────────────────────────────────────────────────
   SUMMARY CARDS
───────────────────────────────────────────────────────────────────────────── */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.summary-3 { grid-template-columns: repeat(3, 1fr); }

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.s-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.s-value { font-size: 22px; font-weight: 700; line-height: 1; }
.s-of    { font-size: 14px; font-weight: 400; color: var(--muted); }
.v-total   { color: var(--text); }
.v-paid    { color: var(--paid); }
.v-late    { color: var(--late); }
.v-promised{ color: var(--promised); }

/* ─────────────────────────────────────────────────────────────────────────────
   ADD FORM
───────────────────────────────────────────────────────────────────────────── */
.add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.form-title {
  font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px;
}
.form-row {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 11px; color: var(--muted); font-weight: 500; }

.form-group input,
.form-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(147,197,253,.25);
}

.fg-name   { flex: 1 1 160px; }
.fg-amount { flex: 0 1 120px; }
.fg-cycle  { flex: 0 1 130px; }
.fg-day    { flex: 0 1 100px; }

.btn-add {
  padding: 8px 20px;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700;
  cursor: pointer; height: 36px; white-space: nowrap; flex-shrink: 0;
  transition: opacity .15s, transform .1s;
}
.btn-add:hover  { opacity: .88; }
.btn-add:active { transform: scale(.97); }
.btn-spotify { background: var(--spotify); color: #fff; }
.btn-netflix { background: var(--netflix); color: #fff; }
.btn-mysubs  { background: var(--mysubs);  color: #fff; }

/* ─────────────────────────────────────────────────────────────────────────────
   TABLE WRAPPER
───────────────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

/* ─────────────────────────────────────────────────────────────────────────────
   OVERVIEW ROWS (shared + mysubs)
───────────────────────────────────────────────────────────────────────────── */
tr.overview-row {
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background .1s;
}
tr.overview-row:hover    { background: var(--surface2); }
tr.overview-row.expanded { background: #f5f7ff; }
tr.overview-row.editing  { background: #fffbeb; cursor: default; }
tr.overview-row td { padding: 13px 14px; vertical-align: middle; }

.td-chevron { width: 28px; padding-right: 0 !important; }
.chevron {
  display: inline-block; font-size: 16px; color: var(--muted-light);
  transition: transform .2s; line-height: 1;
}
.chevron.open { transform: rotate(90deg); color: var(--muted); }

.td-name    { font-weight: 600; }
.td-amount  { font-variant-numeric: tabular-nums; }
.td-history { font-size: 12px; color: var(--muted); }
.per-month  { font-size: 11px; color: var(--muted-light); margin-left: 2px; }

/* My Subs table — no pointer on rows */
#panel-mysubs tr.overview-row { cursor: default; }

/* ─────────────────────────────────────────────────────────────────────────────
   MONTH HEADER ROW
───────────────────────────────────────────────────────────────────────────── */
tr.month-header-row {
  background: #eef1fb;
  border-bottom: 1px solid var(--border-soft);
}
tr.month-header-row td { padding: 6px 14px; }
.month-header-inner {
  display: grid;
  grid-template-columns: 180px 170px 1fr;
  gap: 14px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   MONTH ROWS
───────────────────────────────────────────────────────────────────────────── */
tr.month-row {
  border-bottom: 1px solid var(--border-soft);
  background: #fafbff;
  transition: background .1s;
}
tr.month-row:hover          { background: #f3f5ff; }
tr.month-row td             { padding: 9px 14px; vertical-align: middle; }
tr.month-row.current-month  { background: #f0f9ff; }
tr.month-row.current-month:hover { background: #e8f4ff; }

.td-month-label {
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.current-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #3b82f6; flex-shrink: 0;
}
.badge-current {
  font-size: 10px; font-weight: 700; color: #3b82f6;
  background: #dbeafe; padding: 2px 7px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: .3px;
}
.td-month-notes { padding-right: 16px !important; }
.notes-input {
  width: 100%; background: transparent;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 12px; font-family: inherit;
  padding: 4px 8px; outline: none;
  transition: border-color .15s, background .15s;
}
.notes-input::placeholder { color: var(--muted-light); }
.notes-input:focus { border-color: var(--border); background: var(--surface); color: var(--text); }

tr.spacer-row td {
  height: 6px; background: var(--bg);
  border-bottom: 2px solid var(--border); padding: 0;
}

/* ─────────────────────────────────────────────────────────────────────────────
   STATUS SELECTS
───────────────────────────────────────────────────────────────────────────── */
.status-select {
  border: none; cursor: pointer; font-family: inherit;
  font-size: 12px; font-weight: 700;
  padding: 4px 8px; border-radius: 20px;
  outline: none; appearance: none; -webkit-appearance: none;
  transition: opacity .15s;
}
.status-select:hover { opacity: .85; }
.s-paid     { background: var(--paid-bg);     color: var(--paid);     }
.s-pending  { background: var(--pending-bg);  color: var(--pending);  }
.s-late     { background: var(--late-bg);     color: var(--late);     }
.s-promised { background: var(--promised-bg); color: var(--promised); }

/* ─────────────────────────────────────────────────────────────────────────────
   BADGES
───────────────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-paid     { background: var(--paid-bg);     color: var(--paid);     }
.badge-pending  { background: var(--pending-bg);  color: var(--pending);  }
.badge-late     { background: var(--late-bg);     color: var(--late);     }
.badge-promised { background: var(--promised-bg); color: var(--promised); }

/* cycle badge */
.cycle-badge {
  display: inline-block;
  font-size: 12px; color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px 9px; border-radius: 20px;
}

/* days until badge */
.days-badge {
  display: inline-block;
  font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 20px;
}
.days-badge.urgent { background: var(--late-bg);    color: var(--late);    }
.days-badge.soon   { background: var(--pending-bg); color: var(--pending); }
.days-badge.fine   { background: var(--paid-bg);    color: var(--paid);    }

/* ─────────────────────────────────────────────────────────────────────────────
   ROW ACTION BUTTONS
───────────────────────────────────────────────────────────────────────────── */
.td-actions { display: flex; gap: 6px; align-items: center; }

.btn-icon {
  background: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer;
  padding: 4px 9px; font-size: 13px;
  transition: background .1s, color .1s, border-color .1s;
}
.btn-icon:hover        { background: var(--surface2); color: var(--text); }
.btn-del:hover         { color: var(--late);     border-color: var(--late-bg); }
.btn-save:hover        { color: var(--paid);     border-color: var(--paid-bg); }
.btn-cancel:hover      { color: var(--muted); }

/* ─────────────────────────────────────────────────────────────────────────────
   INLINE EDIT INPUTS
───────────────────────────────────────────────────────────────────────────── */
.edit-input {
  background: var(--surface);
  border: 1px solid #93c5fd; border-radius: var(--radius-sm);
  color: var(--text); padding: 5px 8px;
  font-size: 13px; font-family: inherit; outline: none;
  box-shadow: 0 0 0 3px rgba(147,197,253,.2);
  width: 100%;
}
.edit-select {
  background: var(--surface2);
  border: 1px solid #93c5fd; border-radius: var(--radius-sm);
  color: var(--text); padding: 5px 8px;
  font-size: 13px; font-family: inherit; outline: none;
}
.amount-input { max-width: 100px; }

/* ─────────────────────────────────────────────────────────────────────────────
   EMPTY ROW
───────────────────────────────────────────────────────────────────────────── */
.empty-row td {
  text-align: center; padding: 40px;
  color: var(--muted); font-size: 13px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   TOAST
───────────────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 1000;
}
.toast {
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(6px);
  transition: opacity .25s, transform .25s;
  max-width: 280px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--paid-bg);  color: var(--paid); border: 1px solid #bbf7d0; }
.toast-error   { background: var(--late-bg);  color: var(--late); border: 1px solid #fecaca; }

/* ─────────────────────────────────────────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .summary                { grid-template-columns: 1fr 1fr; }
  .summary-3              { grid-template-columns: 1fr 1fr; }
  .form-row               { flex-direction: column; }
  .month-header-inner     { grid-template-columns: 130px 150px 1fr; }
  .td-history             { display: none; }
}
@media (max-width: 400px) {
  .summary                { grid-template-columns: 1fr; }
  .header-actions .btn-header span { display: none; }
}
