:root { --bg:#0f172a; --card:#111827; --text:#e5e7eb; --muted:#9ca3af; --accent:#2563eb; --danger:#ef4444 }
* { box-sizing:border-box }
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Apple Color Emoji", "Segoe UI Emoji"; background:var(--bg); color:var(--text); min-height:100vh }

/* Login specific styles */
.login-body { display:flex; align-items:center; justify-content:center; background:linear-gradient(135deg, #0f172a 0%, #1e293b 100%) }
.login-wrapper { width:100%; max-width:420px; padding:1rem; display:flex; flex-direction:column; gap:2rem }
.brand { text-align:center }
.brand img.logo { max-width:220px; margin-bottom:1rem; filter: drop-shadow(0 0 10px rgba(255,255,255,0.1)) }
.brand h1 { font-size:1.5rem; margin:0; color:var(--text); font-weight:600 }
.container { padding:2rem; background:var(--card); border-radius:12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); border:1px solid #1f2937 }
.login-footer { text-align:center; color:var(--muted); font-size:0.875rem }
.login-footer p { margin:0.25rem 0 }
.credits { font-size:0.75rem; opacity:0.7 }

/* Global styles */
/* Scoped label style to avoid global breakage */
.grid-form label, .field label, form label, label { display:block; margin:.5rem 0; font-size:0.9rem; color:var(--muted) }

input, select { width:100%; padding:.75rem 1rem; border-radius:8px; border:1px solid #334155; background:#0b1220; color:var(--text); outline:none; transition:border-color .2s }
input:focus, select:focus { border-color:var(--accent) }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); cursor: pointer; }
button { padding:.7rem 1rem; border:none; border-radius:8px; background:var(--accent); color:white; cursor:pointer; font-weight:500; transition:opacity .2s }
button:hover { opacity:0.9 }
button:disabled { opacity:.6; cursor:not-allowed }
.error { color:var(--danger); font-size:0.9rem; margin-top:1rem }
.info { color:var(--muted) }

/* Topbar & Notification Styles */
.topbar { display:flex; align-items:center; justify-content:space-between; padding:1rem 2rem; background:#0b1220; border-bottom:1px solid #1f2937; position:sticky; top:0; z-index:100; flex-wrap: wrap; }
.topbar-brand { display:flex; align-items:center }
.topbar-brand .logo { height:40px; margin-right:1rem; vertical-align:middle }
.topbar-brand h1 { font-size:1.25rem; margin:0 }
.topbar-nav { display:flex; align-items:center; gap:1rem }
.topbar-nav a { color:var(--text); text-decoration:none; transition: color 0.2s; }
.topbar-nav a.active { color:var(--accent); font-weight:bold }
.topbar-nav a:hover { color:var(--accent) }

.burger-btn { display: none; background: transparent; border: none; color: var(--text); font-size: 1.5rem; cursor: pointer; padding: 0.5rem; }

/* Notification Styles */
.notif-wrapper { position: relative; display: inline-block; }
.notif-btn { background:transparent; padding:0.5rem; color:var(--muted); position:relative; border:none; cursor:pointer; display:flex; align-items:center; transition:color .2s }
.notif-btn:hover { color:var(--text) }
.notif-badge { position:absolute; top:0; right:0; background:var(--danger); color:white; font-size:0.7rem; padding:0.1rem 0.35rem; border-radius:10px; min-width:16px; text-align:center; font-weight:bold; line-height:1 }
.notif-dropdown { display:none; position:absolute; top:120%; right:0; width:320px; background:var(--card); border:1px solid #374151; border-radius:8px; box-shadow:0 10px 25px rgba(0,0,0,0.5); z-index:200 }
.notif-dropdown::before { content:''; position:absolute; top:-6px; right:14px; width:12px; height:12px; background:var(--card); border-left:1px solid #374151; border-top:1px solid #374151; transform:rotate(45deg) }
.notif-header { padding:0.75rem 1rem; border-bottom:1px solid #374151; font-weight:600; font-size:0.9rem; color:var(--text) }
.notif-list { max-height:350px; overflow-y:auto }
.notif-item { padding:0.75rem 1rem; border-bottom:1px solid #374151; font-size:0.85rem; color:var(--muted); cursor:default }
.notif-item:last-child { border-bottom:none }
.notif-item:hover { background:rgba(255,255,255,0.03) }
.notif-item.unread { color:var(--text); background:rgba(37, 99, 235, 0.08); border-left:3px solid var(--accent) }

.grid { display:flex; flex-direction:column; gap:2rem; padding:0; width:100% }
.grid-form { display:grid; grid-template-columns: 1fr 1fr; gap:.75rem }
.grid-form input { min-width:0 }
.table-container { padding:0 2rem; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width:100%; border-collapse: separate; border-spacing: 0; margin-top:1rem; table-layout: fixed }
.table th, .table td { border-bottom:1px solid #1f2937; padding:1rem 0.5rem; text-align:left; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table th:last-child, .table td:last-child { overflow: visible; text-overflow: clip; width: 180px; }

.table th { color:var(--muted); font-weight:600; font-size:0.75rem; text-transform:uppercase; letter-spacing:0.05em; background:var(--bg); position:sticky; top:0; z-index: 10 }
.table tbody tr:hover { background-color: rgba(37, 99, 235, 0.05) }

.status-badge { padding: 0.25rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; display: inline-block; }
.view-btn { background: #374151; color: white; padding: 0.4rem 0.8rem; border-radius: 6px; font-size: 0.85rem; border: none; cursor: pointer; white-space: nowrap; margin-left: 0.5rem; }
.view-btn:hover { background: #4b5563; }
.icon-btn { padding: 0.4rem; border-radius: 6px; background: transparent; transition: background 0.2s; color: var(--muted) }
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text) }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed }

.toolbar { display:flex; gap:.5rem; align-items:center; padding:1rem 2rem }
.card { background:var(--card); border:1px solid #1f2937; border-radius:12px; padding:1.5rem; box-shadow: 0 4px 6px rgba(0,0,0,.1); margin:0 2rem }
.pager { margin-top:1rem; display:flex; gap:.5rem; justify-content:center; padding-bottom:2rem }
.pager button { background:#1f2937; padding:0.5rem 0.75rem }
.pager button:disabled { background:var(--accent); opacity:1 }

/* Tabs Styles */
.tabs { display: flex; border-bottom: 1px solid #1f2937; margin-bottom: 1rem; flex-wrap: wrap; }
.tab { padding: 1rem 2rem; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; transition: color 0.2s, border-color 0.2s; }
.tab.active { border-bottom-color: var(--accent); color: var(--text); }
.tab:hover { color: var(--text); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.badge { padding: 0.25rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
.badge-green { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-red { background: rgba(239, 68, 68, 0.2); color: #f87171; }

/* Stats Page Styles - Restored from user backup */
.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
  padding: 1rem 0;
  width: 100%;
}

.chart-card {
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
  display: flex;
  flex-direction: column;
  min-width: 0; /* Fix grid overflow */
}

.chart-card h3 {
  margin-top: 0;
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.chart-card canvas {
    max-width: 100%;
    max-height: 400px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  transition: transform 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
}

.kpi-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--text);
  margin: 0.5rem 0;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Objectives Styles - Restored from user backup */
.obj-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.obj-card {
    background: var(--card);
    border: 1px solid #1f2937;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.obj-title {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 1rem;
    border-bottom: 1px solid #374151;
    padding-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.obj-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.progress-bg {
    flex: 1;
    height: 8px;
    background: #374151;
    border-radius: 4px;
    margin: 0 1rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.5s ease-in-out;
}

.progress-text {
    min-width: 90px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-label { 
    width: 140px; 
    font-size: 0.85rem;
    color: var(--muted);
}

/* Toolbar specific for formations tab */
.toolbar-search { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 1rem; }
.search-box { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

@media (max-width:900px){ 
  .grid-form { grid-template-columns: 1fr }
  .toolbar { flex-direction: column; align-items: stretch }
  .toolbar button, .toolbar input { width: 100% }
  
  /* Responsive Detail Page */
  .detail-grid { grid-template-columns: 1fr !important; gap: 1rem !important; }
  .detail-grid > div { grid-template-columns: 1fr !important; gap: 1rem !important; }
  .detail-grid > div > div { margin-bottom: 1rem; }
  
  /* Responsive Topbar Update */
  .topbar { padding: 0.5rem 1rem; }
  .topbar-brand { margin-bottom: 0; width: auto; justify-content: flex-start; }
  .burger-btn { display: block; }
  
  .topbar-nav { 
      display: none;
      flex-direction: column; 
      gap: 0; 
      width: 100%;
      align-items: stretch;
      margin-top: 1rem;
      border-top: 1px solid #1f2937;
      padding-top: 0.5rem;
  }
  .topbar-nav.open { display: flex; }
  
  .topbar-nav a {
      text-align: left;
      padding: 0.75rem 1rem;
      border-radius: 0;
      background: transparent;
      border-bottom: 1px solid #1f2937;
  }
  .topbar-nav a:last-child { border-bottom: none; }
  .topbar-nav a:hover { background: rgba(255,255,255,0.05); }
  
  .card { margin: 0 1rem }
  .table-container { padding: 0 1rem }
  .table { min-width: 800px } /* Force horizontal scroll on mobile */
  .table th, .table td { padding: 0.75rem 1rem }
  
  /* Stats Grid Responsive */
  .stats-grid {
      grid-template-columns: 1fr !important;
  }

  /* Tabs Responsive */
  .tabs {
      flex-direction: column;
      border-bottom: none;
      gap: 0.5rem;
  }
  .tab {
      width: 100%;
      text-align: center;
      border: 1px solid #1f2937;
      border-radius: 6px;
      padding: 0.75rem;
  }
  .tab.active {
      border-color: var(--accent);
      background: rgba(37, 99, 235, 0.1);
      color: var(--accent);
  }

  /* Toolbar Search Responsive */
  .toolbar-search {
      flex-direction: column;
      align-items: stretch;
  }
  .search-box, .actions {
      width: 100%;
      flex-direction: column;
  }
  .search-box input {
      width: 100% !important;
  }
}

@media (max-width: 600px) {
    .stats-container, .obj-grid {
        grid-template-columns: 1fr;
    }
    .obj-row {
        flex-wrap: wrap;
    }
    .progress-bg {
        width: 100%;
        margin: 0.5rem 0;
        order: 3;
    }
    .stat-label {
        width: auto;
        order: 1;
    }
    .progress-text {
        width: auto;
        order: 2;
    }
    .login-wrapper { padding: 1rem }
    .container { padding: 1.5rem }
}

/* Toggle Switch - NEW */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #374151;
  transition: .4s;
  border-radius: 24px;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}
.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent);
}
.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(26px);
}
