/* ===== ROOT VARIABLES ===== */
:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --success: #34a853;
  --danger: #ea4335;
  --warning: #fbbc04;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --sidebar: #1e293b;
  --sidebar-hover: #334155;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  opacity: 1;
  transition: opacity 0.24s ease, transform 0.24s ease;
}

body.page-enter {
  opacity: 0;
  transform: translateY(8px);
}

body.page-enter.page-ready {
  opacity: 1;
  transform: none;
}

body.page-leaving {
  opacity: 0;
  transform: translateY(8px);
}

.page-loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 3000;
}

.page-loader-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.page-loader-content {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-loader-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(26,115,232,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.page-loader-text {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

/* ===== LOGIN PAGE ===== */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

.login-box {
  background: var(--card);
  padding: 48px 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-box .lock-icon {
  width: 64px;
  height: 64px;
  background: var(--sidebar);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: #fff;
  font-size: 28px;
}

.login-box h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text);
}

.login-box .subtitle {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 14px;
}

.login-box .restricted-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: all 0.2s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.12);
}

.form-help {
  display: block;
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

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

.login-box .btn-primary {
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #2d8e47; }

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

.btn-warning { background: var(--warning); color: #1f2937; }
.btn-warning:hover { background: #f59e0b; }

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-secondary:hover { background: #cbd5e1; }

.btn-sm { padding: 8px 16px; font-size: 13px; }

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

/* ===== LAYOUT ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  height: 100vh;
  top: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header .user-info {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-nav a,
.sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  margin-bottom: 4px;
}

.sidebar-nav a:hover,
.sidebar-nav button:hover,
.sidebar-nav a.active {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav .nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
  padding: 16px 16px 8px;
  font-weight: 700;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer .btn {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.sidebar-footer .btn:hover {
  background: rgba(255,255,255,0.15);
}

.main-content {
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
}

/* ===== CARDS ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

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

.card.card-locked {
  cursor: not-allowed;
  border: 1px dashed var(--border);
}

.card.card-locked:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.card .meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.card .price {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 12px;
}

.card .badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ===== PLAN DETAIL ===== */
.plan-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

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

.additional-products-card {
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  .plan-detail-grid { grid-template-columns: 1fr; }
  .sidebar { width: 100%; position: relative; height: auto; }
  .main-content { margin-left: 0; }
}

.timeline-summary {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid var(--border);
  display: grid;
  gap: 8px;
}

.timeline-summary-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.timeline-summary-row.is-final {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.detail-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.detail-card h2 {
  font-size: 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.table-wrap {
  overflow-x: auto;
}

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

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #f8fafc;
}

tr:hover { background: #f8fafc; }

.total-row {
  font-weight: 700;
  background: #f1f5f9 !important;
}

/* ===== TIMELINE ===== */
.timeline-card {
  grid-column: 1 / -1;
}

.timeline-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

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

.timeline-checkbox {
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: var(--success);
}

.timeline-date { font-weight: 600; min-width: 110px; }
.timeline-countdown {
  min-width: 90px;
  font-size: 13px;
  color: var(--text-secondary);
}
.timeline-countdown.today { color: var(--primary); font-weight: 700; }
.timeline-countdown.past { color: var(--danger); }
.timeline-amount { font-weight: 600; min-width: 80px; }
.timeline-status {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.timeline-source {
  min-width: 170px;
  color: var(--text-secondary);
  font-size: 13px;
}

.timeline-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.status-not-due { background: #e0e7ff; color: #3730a3; }
.status-due { background: #fef3c7; color: #92400e; }
.status-past-due { background: #fee2e2; color: #991b1b; }
.status-paid { background: #dcfce7; color: #166534; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

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

.modal-header h3 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.modal-close:hover { background: var(--bg); }

.modal-body { padding: 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== ADMIN ===== */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--card);
  padding: 6px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  width: fit-content;
}

.admin-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
}

.admin-tab.active {
  background: var(--primary);
  color: #fff;
}

.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* ===== AUDIT LOGS ===== */
.log-entry {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}

.log-entry:last-child { border-bottom: none; }

.log-time {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 160px;
  font-family: monospace;
}

.log-action {
  font-weight: 600;
  min-width: 140px;
}

.log-user {
  color: var(--primary);
  font-weight: 500;
  min-width: 120px;
}

.log-details {
  color: var(--text-secondary);
  flex: 1;
}

/* ===== UTILITIES ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transform: translateY(100px);
  transition: transform 0.3s;
}

.toast.show { transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

.hidden { display: none !important; }

.text-right { text-align: right; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.gap-2 { gap: 12px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
