/* 
 * Catatan Utang - Modern Mobile-Friendly CSS
 * Light & Dark Theme Support via CSS Variables & System Preference
 */

:root {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-header: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-input: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-white: #ffffff;
  
  --border-color: #e2e8f0;
  
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --success-color: #16a34a;
  --success-bg: #dcfce7;
  --success-text: #15803d;
  
  --warning-color: #eab308;
  --warning-bg: #fef9c3;
  --warning-text: #a16207;
  
  --danger-color: #dc2626;
  --danger-bg: #fee2e2;
  --danger-text: #b91c1c;

  --wa-color: #25d366;
  --wa-hover: #128c7e;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --bg-header: #1e293b;
  --bg-hover: #334155;
  --bg-input: #0f172a;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --border-color: #334155;
  
  --primary-light: #1e3a8a;
  
  --success-bg: #064e3b;
  --success-text: #6ee7b7;
  
  --warning-bg: #713f12;
  --warning-text: #fde047;
  
  --danger-bg: #7f1d1d;
  --danger-text: #fca5a5;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

/* Header & Navbar */
.app-header {
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 700;
  font-size: 1.15rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Theme Toggle Button */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background-color: var(--bg-hover);
}

/* Typography & Badges */
h1, h2, h3, h4 {
  color: var(--text-main);
  font-weight: 700;
}

.text-muted {
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-lunas {
  background-color: var(--success-bg);
  color: var(--success-text);
}

.badge-kurang {
  background-color: var(--warning-bg);
  color: var(--warning-text);
}

.badge-belum_lunas {
  background-color: var(--danger-bg);
  color: var(--danger-text);
}

/* Cards & Stats */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stats-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.stats-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
}

.stat-value.primary { color: var(--primary-color); }
.stat-value.danger { color: var(--danger-color); }
.stat-value.success { color: var(--success-color); }

/* Debt Card Layout */
.debt-card {
  padding: 16px;
  margin-bottom: 12px;
}

.debt-card-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.debt-card-info {
  flex: 1;
  min-width: 0;
}

.debt-card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.debt-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  word-break: break-word;
}

.debt-card-meta {
  font-size: 0.825rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.debt-card-amount {
  text-align: right;
  flex-shrink: 0;
}

.amount-total {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
}

.amount-paid {
  font-size: 0.8rem;
  color: var(--success-color);
  font-weight: 600;
}

.amount-remaining {
  font-size: 0.9rem;
  font-weight: 700;
  margin-top: 2px;
}

.text-danger { color: var(--danger-color); }
.text-success { color: var(--success-color); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  min-height: 42px;
}

.btn-primary {
  background-color: var(--primary-color);
  color: var(--text-white);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-whatsapp {
  background-color: var(--wa-color);
  color: white;
}

.btn-whatsapp:hover {
  background-color: var(--wa-hover);
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  min-height: 32px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Debtor List Items */
.debtor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  margin-bottom: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease;
}

.debtor-item:hover {
  border-color: var(--primary-color);
  transform: translateY(-1px);
}

.debtor-info h3 {
  font-size: 1rem;
  margin-bottom: 4px;
}

.debtor-meta {
  font-size: 0.825rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.debtor-amount {
  text-align: right;
}

.debtor-amount .total {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--danger-color);
}

.debtor-amount .lunas {
  color: var(--success-color);
}

/* Phone link styling */
.phone-link {
  color: var(--wa-color);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.phone-link:hover {
  text-decoration: underline;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 500;
}

.alert-success {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid rgba(22, 163, 74, 0.2);
}

.alert-error {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

.alert-info {
  background-color: var(--primary-light);
  color: var(--primary-color);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

/* Modal Popup */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 20px 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .container {
    padding: 12px;
  }
  
  .stats-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .stats-grid.cols-4 {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-card {
    padding: 10px 8px;
  }

  .stat-label {
    font-size: 0.68rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .debtor-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .debtor-amount {
    text-align: left;
    width: 100%;
    border-top: 1px dashed var(--border-color);
    padding-top: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .debt-card {
    padding: 14px 12px;
  }

  .debt-card-main {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
  }

  .debt-card-amount {
    text-align: right;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .amount-total {
    font-size: 1.05rem;
  }

  .amount-remaining {
    font-size: 0.85rem;
  }
}
