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

:root {
  --bg: #0A0C10;
  --surface: #12151C;
  --surface2: #1A1F2B;
  --border: #232836;
  
  /* Accent Colors */
  --accent: #00E5A0;
  --accent-dim: rgba(0, 229, 160, 0.12);
  --accent-glow: rgba(0, 229, 160, 0.25);
  
  --red: #FF4D6A;
  --red-dim: rgba(255, 77, 106, 0.12);
  
  --blue: #4D8EFF;
  --blue-dim: rgba(77, 142, 255, 0.12);
  
  /* Text Colors */
  --text: #F0F4FF;
  --text-muted: #6B7590;
  --text-dim: #3A4056;
  
  /* Status Colors (Matched to JS) */
  --success: #00E5A0; 
  --danger: #FF4D6A;
  --profit-pos: #00E5A0;
  --profit-neg: #FF4D6A;
  
  --font: 'Plus Jakarta Sans', sans-serif;
  --radius: 16px;
  --radius-sm: 10px;

  /* Responsive spacing */
  --side-pad: 16px;
  --content-max: 680px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── AUTH LOCK SCREEN ── */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 30px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  overflow: hidden;
  animation: slideIn 0.3s ease-out;
}

.auth-title { font-size: 22px; font-weight: 800; color: var(--text); margin-top: 24px; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 8px; margin-bottom: 24px; line-height: 1.5; }

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-group .field-label {
  display: block;
  margin-bottom: 8px;
}

.reset-hint {
  display: block;
  margin-top: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-align: center;
  padding: 6px;
  transition: opacity 0.2s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.reset-hint:hover  { opacity: 0.75; }
.reset-hint:active { opacity: 0.5; }

.pin-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 32px;
  letter-spacing: 16px;
  text-align: center;
  color: var(--text);
  padding: 20px;
  font-weight: 800;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  display: block;
}

.pin-input:focus { 
  border-color: var(--accent); 
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Smaller PIN input used inside setup form */
#setupPin,
#setupPinConfirm {
  font-size: 22px;
  letter-spacing: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
}

/* ── MAIN APP WRAPPER ── */
.app-wrapper {
  padding-bottom: 120px;
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ── HEADER ── */
header {
  padding: 20px var(--side-pad) 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.logo span { color: var(--accent); }

.date-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex-shrink: 1;
  max-width: 180px;
}

/* ── DASHBOARD GREETING ── */
.dashboard-greeting {
  margin: 20px var(--side-pad) 0;
}

.greeting-title {
  font-size: clamp(18px, 5vw, 22px);
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.greeting-name { color: var(--accent); }

.greeting-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ── PROFIT CARD ── */
.profit-card {
  margin: 20px var(--side-pad) 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 20px 20px;
  position: relative;
  overflow: hidden;
  transition: all 0.4s ease;
}

.profit-card::before {
  content: '';
  position: absolute;
  top: -60px;
  right: -60px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--accent-glow);
  filter: blur(60px);
  transition: background 0.4s ease;
  pointer-events: none;
}

.profit-card.loss::before { background: rgba(255,77,106,0.2); }

.profit-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.profit-amount {
  font-size: clamp(32px, 8vw, 48px);
  font-weight: 800;
  color: var(--profit-pos);
  line-height: 1.1;
  letter-spacing: -1px;
  transition: color 0.4s ease;
  word-break: break-word;
  overflow-wrap: break-word;
}

.profit-amount.loss { color: var(--profit-neg); }

.profit-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
  line-height: 1.4;
}

.profit-pills {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.pill {
  flex: 1;
  min-width: 80px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.pill-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.pill-value {
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 800;
  letter-spacing: -0.5px;
  word-break: break-word;
  overflow-wrap: break-word;
}

.pill-value.green { color: var(--accent); }
.pill-value.red   { color: var(--red); }
.pill-value.blue  { color: var(--blue); }

/* ── SECTION TITLE & CARDS ── */
.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 24px var(--side-pad) 12px;
}

.input-card {
  margin: 0 var(--side-pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tab-bar { display: flex; border-bottom: 1px solid var(--border); }

.tab {
  flex: 1;
  padding: 14px 10px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  background: transparent;
  border: none;
  transition: all 0.2s;
  font-family: var(--font);
  white-space: nowrap;
}

.tab.active-sale    { color: var(--accent); border-bottom: 2px solid var(--accent); }
.tab.active-expense { color: var(--red);    border-bottom: 2px solid var(--red); }

.tab-panel          { display: none; padding: 16px; }
.tab-panel.active   { display: block; animation: fadeIn 0.3s ease; }

/* ── FORM INPUTS ── */
.field-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.field { flex: 1; min-width: 120px; }

input[type="text"],
input[type="number"],
input[type="tel"],
input[type="password"],
textarea,
.setup-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 14px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder,
textarea::placeholder,
.setup-input::placeholder {
  color: var(--text-dim);
  font-weight: 500;
}

input:focus, textarea:focus { border-color: var(--text-muted); }
.sale-panel input:focus     { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.expense-panel input:focus  { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-dim); }

.line-preview {
  background: var(--accent-dim);
  border: 1px solid rgba(0,229,160,0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 700;
  min-height: 42px;
  word-break: break-word;
  transition: all 0.3s ease;
}

.line-preview.expense {
  background: var(--red-dim);
  border-color: rgba(255,77,106,0.2);
  color: var(--red);
}

/* ── BUTTONS ── */
.btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-sale    { background: var(--accent); color: #000; }
.btn-sale:active    { transform: scale(0.97); background: #00c98d; }
.btn-expense { background: var(--red); color: #fff; }
.btn-expense:active { transform: scale(0.97); background: #e03355; }
.btn-submit { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

/* ── NOTES ── */
.notes-wrap { margin: 0 var(--side-pad); }

textarea {
  resize: none;
  height: 90px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}

/* ── LEDGER FEED ── */
.ledger { margin: 0 var(--side-pad); }

.ledger-empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
}

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

.ledger-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.25s ease;
}

.ledger-item-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 2px; word-break: break-word; }
.ledger-item-meta { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.ledger-item-left  { flex: 1; min-width: 0; }
.ledger-item-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; text-align: right; }

/* Status Classes matching the JS logic */
span.sale { color: var(--success); }
span.expense { color: var(--danger); }

/* ── SUBMIT FOOTER ── */
.submit-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px max(env(safe-area-inset-bottom, 0px), 16px);
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  z-index: 100;
}

.submit-wrap > * {
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}

.btn-submit {
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #00E5A0, #00c98d);
  color: #000;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 32px rgba(0,229,160,0.25);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: all 0.2s;
}

.btn-submit:active { transform: scale(0.98); }

.whatsapp-icon {
  width: 22px;
  height: 22px;
  background: #000;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

/* ── TOAST NOTIFICATIONS ── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: var(--accent);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 100px;
  z-index: 999;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 10px 30px rgba(0, 229, 160, 0.3);
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* Logout text */
.logout-text {
  text-align: center;
  margin-top: 30px;
  font-size: 12px;
  font-weight: 600;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── ANIMATIONS ── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ══════════════════════════════════════
   RESPONSIVE BREAKPOINTS
══════════════════════════════════════ */

/* Very small phones (< 360px) */
@media (max-width: 359px) {
  :root { --side-pad: 12px; }
  .profit-amount { font-size: 28px; letter-spacing: -0.5px; }
  .pill { min-width: 70px; padding: 8px 10px; }
  .pill-value { font-size: 13px; }
  .tab { font-size: 12px; padding: 12px 6px; }
  .input-row { flex-direction: column; }
  .field { min-width: 100%; }
  input[type="text"], input[type="number"], input[type="tel"], .setup-input { font-size: 14px; padding: 12px; }
  .btn { font-size: 14px; padding: 14px; }
  .btn-submit { font-size: 13px; padding: 15px; }
  .date-badge { font-size: 10px; padding: 5px 8px; max-width: 150px; }
}

/* Standard phones (360px – 479px) */
@media (min-width: 360px) and (max-width: 479px) {
  .profit-amount { font-size: clamp(30px, 9vw, 44px); }
}

/* Large phones / small tablets (480px – 767px) */
@media (min-width: 480px) {
  :root { --side-pad: 20px; }
  .profit-amount { font-size: 44px; }
  .tab-panel { padding: 20px; }
  .btn-submit { font-size: 16px; }
}

/* Tablet portrait (768px – 1023px) */
@media (min-width: 768px) {
  :root { --side-pad: 24px; --content-max: 680px; }
  header { padding: 28px var(--side-pad) 0; }
  .logo { font-size: 14px; }
  .date-badge { font-size: 12px; padding: 7px 14px; max-width: none; }
  .profit-card { padding: 32px 28px 24px; }
  .profit-amount { font-size: 52px; }
  .pill { padding: 14px 16px; }
  .pill-value { font-size: 20px; }
  .section-title { padding: 28px var(--side-pad) 14px; }
  .tab { font-size: 14px; }
  .tab-panel { padding: 24px; }
  input[type="text"], input[type="number"], input[type="tel"], .setup-input { font-size: 16px; }
  .btn { font-size: 16px; padding: 17px; }
  textarea { height: 110px; }
  .ledger-item { padding: 14px 18px; }
  .ledger-item-name  { font-size: 15px; }
  .ledger-item-amount { font-size: 16px; }
  .submit-wrap { padding: 20px 24px max(env(safe-area-inset-bottom, 0px), 20px); }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  :root { --content-max: 700px; }
  body { padding-top: 0; }
  .app-wrapper { padding-top: 12px; }
  header { padding: 32px var(--side-pad) 0; }
  .profit-amount { font-size: 56px; letter-spacing: -2px; }
  .profit-card:hover { border-color: rgba(0,229,160,0.3); }
  .btn-sale:hover    { background: #00f0aa; }
  .btn-expense:hover { background: #ff2d55; }
  .btn-submit:hover  { transform: translateY(-1px); box-shadow: 0 12px 40px rgba(0,229,160,0.35); }
  .submit-wrap { padding: 20px 0 28px; }
}

/* Safe area support */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .app-wrapper { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
  .submit-wrap { padding-bottom: max(env(safe-area-inset-bottom), 16px); }
}

/* ── DATE DROPDOWN ── */
.date-badge {
  transition: opacity 0.2s, background 0.2s;
}

.date-badge:hover {
  background: var(--surface2);
}

.date-badge:active {
  opacity: 0.7;
}

.date-dropdown {
  position: absolute;
  top: 65px;
  right: var(--side-pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 220px;
  max-height: 300px;
  z-index: 200;
  box-shadow: 0 15px 40px rgba(0,0,0,0.6);
  display: flex; /* Changed from display:none so JS can toggle it */
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.2s ease;
}

.dropdown-header {
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.date-list {
  overflow-y: auto;
  max-height: 250px;
}

.date-item {
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.date-item:last-child {
  border-bottom: none;
}

.date-item:hover {
  background: var(--surface2);
}

.date-item.active {
  color: var(--accent);
  background: var(--accent-dim);
}