/* ==========================================================================
   Bill Tracker - Modern, Responsive, Dark & Light Mode Stylesheet
   ========================================================================== */

:root {
  /* Light Theme */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --border-subtle: #edf2f7;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;
  
  --success: #10b981;
  --success-hover: #059669;
  --success-bg: #ecfdf5;
  --success-text: #065f46;
  
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: 0.18s ease-in-out;
}

[data-theme="dark"] {
  /* Dark Theme */
  --bg-primary: #090d16;
  --bg-surface: #111827;
  --bg-surface-hover: #1f2937;
  --border-color: #1f2937;
  --border-subtle: #162032;
  
  --text-primary: #f9fafb;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: #1e293b;
  --primary-border: #2563eb;
  
  --success: #10b981;
  --success-hover: #34d399;
  --success-bg: #064e3b;
  --success-text: #a7f3d0;
  
  --warning: #fbbf24;
  --warning-bg: #78350f;
  --warning-text: #fde68a;
  
  --danger: #f87171;
  --danger-hover: #ef4444;
  --danger-bg: #7f1d1d;
  --danger-text: #fecaca;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

/* Layout Containers */
.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

main.main-content {
  flex: 1 0 auto;
  padding: 2rem 0 3rem;
}

/* Header & Navbar */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text-primary);
  text-decoration: none;
}

.nav-brand:hover {
  text-decoration: none;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.nav-desktop {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav-link {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-decoration: none;
}

.nav-link:hover, .nav-link.active {
  color: var(--primary);
  background-color: var(--bg-surface-hover);
  text-decoration: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Theme Toggle Button */
.btn-theme-toggle {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.45rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  transition: all var(--transition);
}

.btn-theme-toggle:hover {
  background-color: var(--border-color);
}

.theme-icon-light, .theme-icon-dark {
  width: 20px;
  height: 20px;
  display: none;
}

[data-theme="light"] .theme-icon-dark {
  display: block;
}

[data-theme="dark"] .theme-icon-light {
  display: block;
}

/* Hamburger Toggle Button */
.nav-hamburger {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  width: 40px;
  height: 40px;
  position: relative;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background-color: var(--text-primary);
  margin: 5px auto;
  transition: all 0.25s ease;
  border-radius: 2px;
}

.nav-hamburger.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-hamburger.open span:nth-child(2) {
  opacity: 0;
}

.nav-hamburger.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Mobile Drawer */
.mobile-nav-drawer {
  display: none;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
}

.mobile-nav-drawer.open {
  display: block;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.mobile-nav-drawer .nav-link {
  display: block;
  padding: 0.75rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

/* Mobile Navigation Breakpoint */
@media (max-width: 768px) {
  .nav-desktop {
    display: none;
  }
  .nav-hamburger {
    display: block;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  color: #ffffff;
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
}

.btn-success:hover {
  background-color: var(--success-hover);
  color: #ffffff;
}

.btn-secondary {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-outline-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-outline-danger:hover {
  background-color: var(--danger);
  color: #ffffff;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Cards */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Alerts */
.alerts-container {
  margin-bottom: 1.5rem;
}

.alert {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid transparent;
}

.alert-success {
  background-color: var(--success-bg);
  border-color: var(--success);
  color: var(--success-text);
}

.alert-danger {
  background-color: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger-text);
}

.alert-warning {
  background-color: var(--warning-bg);
  border-color: var(--warning);
  color: var(--warning-text);
}

.alert-info {
  background-color: var(--primary-subtle);
  border-color: var(--primary-border);
  color: var(--text-primary);
}

.alert-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  padding: 0 0.25rem;
}

.alert-close:hover {
  opacity: 1;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-value.highlight {
  color: var(--primary);
}

.stat-value.danger {
  color: var(--danger);
}

.stat-value.warning {
  color: var(--warning);
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.form-check input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Reminder Chips / Tags */
.reminder-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: bold;
  padding: 0 0.15rem;
  line-height: 1;
}

.chip-remove:hover {
  color: var(--danger);
}

.quick-offsets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-overdue {
  background-color: var(--danger-bg);
  color: var(--danger);
}

.badge-today {
  background-color: var(--warning-bg);
  color: var(--warning);
}

.badge-upcoming {
  background-color: var(--primary-subtle);
  color: var(--primary);
}

.badge-normal {
  background-color: var(--bg-surface-hover);
  color: var(--text-muted);
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
  background-color: var(--bg-surface);
}

.table th {
  background-color: var(--bg-surface-hover);
  padding: 0.85rem 1rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background-color: var(--bg-surface-hover);
}

/* Auth Cards */
.auth-wrapper {
  max-width: 440px;
  margin: 3rem auto;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Bill List Grid */
.bills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.bill-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}

.bill-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.bill-card.overdue {
  border-left: 4px solid var(--danger);
}

.bill-card.today {
  border-left: 4px solid var(--warning);
}

.bill-card.upcoming {
  border-left: 4px solid var(--primary);
}

.bill-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.bill-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
}

.bill-amount {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.bill-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.bill-meta-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.bill-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  animation: modalScale 0.2s ease;
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-title {
  font-size: 1.15rem;
  font-weight: 600;
}

/* Footer */
.app-footer {
  flex-shrink: 0;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 1.25rem 0;
  margin-top: auto;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.footer-separator {
  color: var(--border-color);
}

.app-footer a {
  color: var(--text-secondary);
}

.app-footer a:hover {
  color: var(--primary);
}

/* QR Code Display */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 1.5rem 0;
  padding: 1.5rem;
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.qr-image {
  max-width: 220px;
  max-height: 220px;
}

.secret-code-display {
  font-family: monospace;
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  background: var(--bg-surface-hover);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  margin-top: 0.75rem;
  color: var(--text-primary);
  user-select: all;
}
