:root {
  --blue-50: #eff6ff; --blue-100: #dbeafe; --blue-200: #bfdbfe;
  --blue-300: #93c5fd; --blue-400: #60a5fa; --blue-500: #3b82f6;
  --blue-600: #2563eb; --blue-700: #1d4ed8;
  --bg-body: #0a1224; --bg-sidebar: #0c1a32; --bg-main: #0d152b;
  --text-main: #e6ecff; --text-soft: #9fb7e3;
  --radius-lg: 14px; --radius-md: 10px;
  --shadow-card: 0 15px 40px rgba(37, 99, 235, 0.25);
  --shadow-glow: 0 0 18px rgba(59, 130, 246, 0.5);
  --transition-fast: 0.18s ease;
}

* { box-sizing: border-box; }

body {
  margin: 0; font-family: system-ui, sans-serif;
  background: radial-gradient(circle at top, #1e3a8a 0%, #020617 60%, #000 100%);
  color: var(--text-main);
  /* Prevent horizontal scroll on body */
  overflow-x: hidden; 
}

/* ===== DESKTOP LAYOUT (Default) ===== */
.app { 
  display: none; /* Hidden until login */
  gap: 16px; 
  padding: 18px; 
  max-width: 1500px; 
  margin: auto; 
  min-height: 100vh; 
}

.sidebar {
  width: 250px; background: linear-gradient(160deg, #0d1c38, #050816);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; border: 1px solid rgba(96, 165, 250, 0.25);
  flex-shrink: 0; /* Prevent shrinking */
}

.logo {
  font-size: 20px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  margin-bottom: 22px; background: linear-gradient(90deg, #60a5fa, #3b82f6);
  background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.nav-btn {
  padding: 9px 12px; margin-bottom: 8px; border-radius: var(--radius-md);
  border: 1px solid transparent; background: transparent; color: var(--text-soft);
  text-align: left; cursor: pointer; font-size: 14px; transition: var(--transition-fast);
}
.nav-btn:hover { background: rgba(59, 130, 246, 0.16); border-color: rgba(96, 165, 250, 0.6); color: var(--text-main); }
.nav-btn.active {
  background: rgba(59, 130, 246, 0.25); border-color: var(--blue-500); color: var(--blue-50);
  box-shadow: inset 0 0 12px rgba(59, 130, 246, 0.5);
}

.sidebar p { margin-top: auto; font-size: 11px; color: var(--text-soft); }

main {
  flex: 1; background: linear-gradient(180deg, #0f172a, #020617);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-card);
  border: 1px solid rgba(30, 64, 175, 0.4);
  overflow: hidden; /* Prevents content spill */
}

.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

h1 { font-size: 24px; margin: 0 0 14px; color: var(--blue-100); }
h2 { font-size: 18px; margin: 18px 0 10px; color: var(--blue-200); }
h3 { font-size: 14px; color: var(--blue-200); margin: 0 0 6px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }

.card {
  background: rgba(15, 23, 42, 0.9); border-radius: 14px; padding: 12px;
  border: 1px solid rgba(96, 165, 250, 0.3); position: relative; overflow: hidden;
  box-shadow: var(--shadow-card); transition: var(--transition-fast);
}
/* Fix for click-through issue */
.card::before { 
  content: ""; position: absolute; inset: -40%; 
  background: radial-gradient(circle at top left, rgba(96, 165, 250, 0.4), transparent 60%);
  pointer-events: none; z-index: 0;
}
.card > * { position: relative; z-index: 1; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.card p { font-size: 26px; font-weight: 700; margin: 4px 0 0; }

.two-col { 
  display: grid; 
  /* CHANGE: Left column is fixed 320px, Right column takes ALL remaining space (1fr) */
  grid-template-columns: 320px 1fr; 
  gap: 20px; 
  align-items: start; /* Prevents the form from stretching vertically if the table is long */
}

/* On Mobile/Tablet: Stack them cleanly */
@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr; /* Stack vertically */
  }
}

.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 12px; margin-bottom: 4px; color: var(--text-soft); }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 8px 9px; font-size: 13px; border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.5); background: rgba(15, 23, 42, 0.85);
  color: var(--text-main); outline: none; transition: var(--transition-fast);
}
.form-row input:focus, .form-row textarea:focus, .form-row select:focus {
  border-color: var(--blue-400); box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.8);
}

.table {
  width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 12px;
  background: rgba(15, 23, 42, 0.9); border-radius: 12px; overflow: hidden;
  border: 1px solid rgba(55, 65, 81, 0.9);
}
.table th, .table td { padding: 8px 9px; border-bottom: 1px solid rgba(31, 41, 55, 1); }
.table th { background: rgba(30, 64, 175, 0.7); color: var(--blue-100); text-align: left; }
.table tr:hover td { background: rgba(37, 99, 235, 0.25); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 7px 13px;
  border-radius: 999px; border: none; cursor: pointer; font-size: 12px;
  margin-top: 4px; margin-right: 4px; transition: var(--transition-fast); text-decoration: none;
}
.btn-primary { background: linear-gradient(90deg, var(--blue-500), var(--blue-600)); color: #fff; box-shadow: 0 4px 15px rgba(59, 130, 246, 0.6); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(59, 130, 246, 0.8); }
.btn-secondary { background: rgba(30, 64, 175, 0.7); color: var(--blue-100); border: 1px solid rgba(129, 140, 248, 0.7); }
.btn-secondary:hover { background: rgba(37, 99, 235, 0.8); }
.btn-danger { background: linear-gradient(90deg, #ef4444, #b91c1c); color: white; }
.btn-small { font-size: 11px; padding: 4px 9px; }

.tag { padding: 3px 9px; border-radius: 999px; font-size: 11px; color: #fff; }
.tag-active { background: #22c55e; }
.tag-expiring { background: #f59e0b; }
.tag-expired { background: #ef4444; }

.error, .success { padding: 8px 10px; border-radius: 8px; font-size: 12px; margin-bottom: 8px; }
.error { background: rgba(239, 68, 68, 0.25); border-left: 4px solid #ef4444; }
.success { background: rgba(34, 197, 94, 0.25); border-left: 4px solid #22c55e; }

/* Login Screen */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top, #1e3a8a 0%, #020617 60%, #000 100%); z-index: 999;
}
.login-card {
  background: rgba(15, 23, 42, 0.95); border-radius: 16px; padding: 24px 28px;
  border: 1px solid rgba(96, 165, 250, 0.4); box-shadow: 0 20px 50px rgba(15, 23, 42, 0.8);
  text-align: center; max-width: 320px;
}
.login-card h1 { margin: 0 0 8px; font-size: 20px; color: var(--blue-100); }
.login-card p { margin: 0 0 16px; font-size: 13px; color: var(--text-soft); }

/* White Calendar Icons */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator { 
  filter: invert(1); opacity: 0.8; cursor: pointer; transition: 0.2s; 
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover { 
  opacity: 1; transform: scale(1.1); 
}

/* =========================================
   📱 MOBILE RESPONSIVE DESIGN
   ========================================= */
@media (max-width: 768px) {
  /* 1. Layout Reset */
  .app {
    flex-direction: column;
    padding: 0;
    gap: 0;
    width: 100%;
  }

  /* 2. Sticky Horizontal Navbar */
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto; /* Horizontal scroll */
    white-space: nowrap;
    padding: 12px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid rgba(96, 165, 250, 0.25);
    position: sticky;
    top: 0;
    z-index: 100;
    background: #0a1224; /* Solid BG prevents transparency issues */
    align-items: center;
  }

  .logo {
    font-size: 16px;
    margin-bottom: 0;
    margin-right: 15px;
    flex-shrink: 0; /* Logo doesn't shrink */
  }

  .nav-btn {
    margin-bottom: 0;
    margin-right: 8px;
    padding: 6px 12px;
    flex-shrink: 0; /* Buttons don't shrink */
    font-size: 13px;
  }

  /* Hide "powered by" on mobile to save space */
  .sidebar p { display: none; }

  /* 3. Main Content Area */
  main {
    border-radius: 0;
    border: none;
    background: transparent; /* Let body gradient show */
    padding: 15px;
    padding-bottom: 80px; /* Extra space for scrolling */
  }

  /* 4. Grid & Forms Stack */
  .two-col {
    grid-template-columns: 1fr; /* Stack columns vertically */
    gap: 20px;
  }

  .cards {
    grid-template-columns: 1fr; /* 1 Card per row on phone */
  }

  /* 5. Scrollable Tables */
  /* We make the container scrollable */
  div:has(> .table), 
  section > div {
    overflow-x: auto;
  }
  
  .table {
    min-width: 600px; /* Force table width so it scrolls */
  }

  /* 6. Typography Tweaks */
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }
}