/* ============================================================
   Renewal Reminder — Custom Styles
   Built with Tailwind CSS v4 (via CDN) + Shoelace
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-danger: #dc2626;
  --color-warning: #f59e0b;
  --color-success: #16a34a;
  --color-info: #0891b2;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --radius: 0.5rem;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}

.dark {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-border: #334155;
  --color-text: #f1f5f9;
  --color-text-muted: #94a3b8;
}

/* ── Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  transition: background-color .3s, color .3s;
  min-height: 100vh;
}

/* ── Loading Overlay ────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--color-bg);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 1rem;
}
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pages ──────────────────────────────────────────────────── */
.page {
  display: none;
}
.page.active {
  display: block;
}

/* ── App Shell ──────────────────────────────────────────────── */
#app-shell {
  display: none;
  flex-direction: column;
  min-height: 100vh;
}
#app-shell.active {
  display: flex;
}

/* ── Header ─────────────────────────────────────────────────── */
#header {
  position: sticky; top: 0; z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

/* ── Navigation ─────────────────────────────────────────────── */
.nav-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  background: none; border: none;
  text-decoration: none;
}
.nav-item:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--color-primary);
}
.nav-item.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--color-primary);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge-overdue {
  background: #fef2f2; color: #dc2626;
  border: 1px solid #fecaca;
}
.badge-1day {
  background: #fff7ed; color: #c2410c;
  border: 1px solid #fed7aa;
}
.badge-3days {
  background: #fffbeb; color: #b45309;
  border: 1px solid #fde68a;
}
.badge-1week {
  background: #fefce8; color: #92400e;
  border: 1px solid #fef08a;
}
.badge-2weeks {
  background: #f0fdf4; color: #166534;
  border: 1px solid #bbf7d0;
}
.badge-1month {
  background: #eff6ff; color: #1e40af;
  border: 1px solid #bfdbfe;
}
.badge-safe {
  background: #f0fdf4; color: #166534;
  border: 1px solid #bbf7d0;
}
.badge-archived {
  background: #f1f5f9; color: #475569;
  border: 1px solid #e2e8f0;
}

.dark .badge-overdue { background: #450a0a; color: #f87171; border-color: #7f1d1d; }
.dark .badge-1day { background: #431407; color: #fb923c; border-color: #9a3412; }
.dark .badge-3days { background: #451a03; color: #fbbf24; border-color: #92400e; }
.dark .badge-1week { background: #422006; color: #fcd34d; border-color: #a16207; }
.dark .badge-2weeks { background: #052e16; color: #4ade80; border-color: #14532d; }
.dark .badge-1month { background: #172554; color: #60a5fa; border-color: #1e3a8a; }
.dark .badge-safe { background: #052e16; color: #4ade80; border-color: #14532d; }
.dark .badge-archived { background: #1e293b; color: #94a3b8; border-color: #334155; }

/* ── Renewal Row ────────────────────────────────────────────── */
.renewal-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 1rem;
}
.renewal-row:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
  transform: translateY(-1px);
}
.renewal-row.overdue-row {
  border-left: 3px solid #dc2626;
}
.renewal-row.urgent-row {
  border-left: 3px solid #f59e0b;
}
.renewal-row.warning-row {
  border-left: 3px solid #eab308;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s;
  text-decoration: none;
}
.btn-primary {
  background: var(--color-primary); color: white;
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-bg);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.btn-danger {
  background: var(--color-danger); color: white;
}
.btn-danger:hover { background: #b91c1c; }

.btn-ghost {
  background: transparent; color: var(--color-text-muted);
}
.btn-ghost:hover {
  background: rgba(0,0,0,.05); color: var(--color-text);
}
.dark .btn-ghost:hover { background: rgba(255,255,255,.05); }

/* ── Form Elements ──────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block; font-size: 0.875rem; font-weight: 500;
  color: var(--color-text-muted); margin-bottom: 0.375rem;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-textarea { resize: vertical; min-height: 100px; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 10000; display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  min-width: 250px; max-width: 400px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast.info { background: #eff6ff; color: #1e40af; border-left: 4px solid #2563eb; }
.toast.success { background: #f0fdf4; color: #166534; border-left: 4px solid #16a34a; }
.toast.warning { background: #fffbeb; color: #92400e; border-left: 4px solid #f59e0b; }
.toast.error { background: #fef2f2; color: #991b1b; border-left: 4px solid #dc2626; }
.dark .toast.info { background: #172554; color: #93c5fd; border-left-color: #3b82f6; }
.dark .toast.success { background: #052e16; color: #86efac; border-left-color: #22c55e; }
.dark .toast.warning { background: #451a03; color: #fcd34d; border-left-color: #f59e0b; }
.dark .toast.error { background: #450a0a; color: #fca5a5; border-left-color: #ef4444; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
  background: var(--color-surface);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: 0.5rem;
}

/* ── Sidebar ────────────────────────────────────────────────── */
#detail-panel {
  position: fixed; top: 0; right: -100%;
  width: min(420px, 100vw);
  height: 100vh;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: -8px 0 32px rgba(0,0,0,.15);
  z-index: 300;
  transition: right 0.3s ease;
  overflow-y: auto;
}
#detail-panel.open { right: 0; }
#detail-panel-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 299;
  background: rgba(0,0,0,.4);
}
#detail-panel-backdrop.open { display: block; }

/* ── Charts ─────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

/* ── Skeleton Loading ───────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, rgba(255,255,255,.3) 50%, var(--color-border) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { to { background-position: -400% 0; } }

/* ── Empty State ────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 4rem 2rem;
  color: var(--color-text-muted);
  text-align: center;
}
.empty-state-icon {
  font-size: 3rem; margin-bottom: 1rem; opacity: .5;
}

/* ── Search & Filter Bar ────────────────────────────────────── */
#filter-bar {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}
#filter-bar.open { display: flex; }

.filter-chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}
.filter-chip:hover, .filter-chip.active {
  background: var(--color-primary);
  color: white; border-color: var(--color-primary);
}

/* ── Progress Bar ───────────────────────────────────────────── */
.progress-bar {
  height: 6px; background: var(--color-border); border-radius: 9999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 9999px;
  transition: width 0.5s ease;
}

/* ── Dark Mode Adjustments ──────────────────────────────────── */
.dark .card,
.dark .stat-card,
.dark .renewal-row { background: var(--color-surface); border-color: var(--color-border); }

.dark .form-input,
.dark .form-select,
.dark .form-textarea {
  background: #1e293b; border-color: #334155; color: #f1f5f9;
}
.dark .form-input::placeholder { color: #64748b; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── Auth Page ──────────────────────────────────────────────── */
#page-auth {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}
#page-auth.active { display: flex; }
.dark #page-auth {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 2);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%; max-width: 420px;
}

/* ── Mobile Menu ────────────────────────────────────────────── */
#mobile-menu {
  position: fixed; inset: 0; z-index: 150;
  background: var(--color-surface);
  padding: 1rem;
  overflow-y: auto;
}
#mobile-menu.hidden { display: none; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .renewal-row {
    flex-wrap: wrap;
  }
  .modal-content {
    max-height: 95vh;
    border-radius: var(--radius);
    margin: 0;
    max-width: 100%;
  }
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
}

/* ── Notification Bell ──────────────────────────────────────── */
#notif-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--color-danger); color: white;
  font-size: 0.65rem; font-weight: 700;
  width: 18px; height: 18px;
  border-radius: 9999px;
  display: none; align-items: center; justify-content: center;
  border: 2px solid var(--color-surface);
}

/* ── Transitions ────────────────────────────────────────────── */
.fade-in { animation: fadeIn 0.3s ease; }
.slide-in { animation: slideIn 0.3s ease; }

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  #header, #mobile-menu, #detail-panel, #toast-container { display: none !important; }
  body { background: white; color: black; }
}
