/* =============================================
   Intelligent Management System - Stylesheet
   Professional Light Theme
   ============================================= */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f2f5;
  color: #222;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Variables ---- */
:root {
  --primary: #1a73e8;
  --primary-dark: #1558c0;
  --primary-light: #e8f0fe;
  --success: #28a745;
  --success-light: #d4edda;
  --warning: #fd7e14;
  --warning-light: #fff3cd;
  --danger: #dc3545;
  --danger-light: #f8d7da;
  --secondary: #6c757d;
  --light: #f8f9fa;
  --dark: #343a40;
  --border: #dee2e6;
  --sidebar-width: 240px;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #334155;
  --sidebar-active: #1a73e8;
  --header-height: 58px;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.10);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
}

/* ---- Layout ---- */
.app-wrapper { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
}
.sidebar-logo {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-logo .app-name {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .3px;
  line-height: 1.3;
}
.sidebar-logo .app-sub { font-size: .72rem; color: #94a3b8; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 10px 0; }
.sidebar-section-label {
  font-size: .68rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 12px 20px 4px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .88rem;
  transition: all .18s;
  border-radius: 0;
  position: relative;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.sidebar-nav a .nav-icon { width: 18px; text-align: center; font-size: .9rem; opacity: .9; }
.sidebar-nav a .badge-count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ---- Overlay ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 199;
}
.sidebar-overlay.show { display: block; }

/* ---- Header ---- */
.header {
  position: fixed;
  top: 0; left: var(--sidebar-width); right: 0;
  height: var(--header-height);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  gap: 12px;
  box-shadow: var(--shadow);
}
.header .hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: #555; padding: 4px;
}
.header .page-title { font-size: 1.05rem; font-weight: 600; color: #1e293b; flex: 1; }
.header .header-actions { display: flex; align-items: center; gap: 12px; }
.notif-btn {
  position: relative; background: none; border: none; cursor: pointer;
  font-size: 1.2rem; color: #555; padding: 4px 8px;
  border-radius: var(--radius);
  transition: background .15s;
}
.notif-btn:hover { background: #f1f5f9; }
.notif-badge {
  position: absolute; top: 0; right: 2px;
  background: var(--danger); color: #fff;
  font-size: .62rem; font-weight: 700;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.notif-badge.blink { animation: blink 1.2s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer;
  padding: 5px 10px; border-radius: var(--radius);
  font-size: .88rem; color: #333;
  transition: background .15s;
}
.user-btn:hover { background: #f1f5f9; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .82rem;
}
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  display: none; z-index: 300;
}
.user-dropdown.show { display: block; }
.user-dropdown a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  color: #333; text-decoration: none;
  font-size: .88rem;
  transition: background .15s;
}
.user-dropdown a:hover { background: #f8f9fa; }
.user-dropdown hr { margin: 4px 0; border-color: var(--border); }

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  flex: 1;
  min-height: calc(100vh - var(--header-height));
  padding: 24px;
}

/* ---- Page Header ---- */
.page-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 1.35rem; font-weight: 700; color: #1e293b; flex: 1; }
.page-header .header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Cards ---- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .95rem;
  color: #1e293b;
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 18px; }

/* ---- KPI / Stat Cards ---- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: #fff; border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.stat-card .stat-label { font-size: .78rem; color: #64748b; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-card .stat-sub { font-size: .75rem; color: #94a3b8; }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.secondary .stat-value { color: var(--secondary); }
.stat-card .stat-icon { font-size: 1.5rem; opacity: .5; margin-bottom: 4px; }

/* ---- Filters Bar ---- */
.filters-bar {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.filters-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px; margin-bottom: 12px;
}
.filters-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box input { padding-left: 36px; }
.search-box .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: .9rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; font-size: .88rem; font-weight: 500;
  border: none; border-radius: var(--radius); cursor: pointer;
  text-decoration: none; transition: all .18s;
  line-height: 1.4;
}
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-xs { padding: 3px 8px; font-size: .75rem; }
.btn-lg { padding: 10px 22px; font-size: .95rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #218838; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #e07611; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: #5a6268; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: #333; }
.btn-outline:hover { background: #f8f9fa; }
.btn-light { background: #f1f5f9; color: #334155; border: 1px solid #e2e8f0; }
.btn-light:hover { background: #e2e8f0; }
.btn-icon { padding: 6px 10px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: .85rem; font-weight: 600;
  color: #374151; margin-bottom: 5px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; padding: 9px 12px; font-size: .88rem;
  border: 1px solid #d1d5db; border-radius: var(--radius);
  background: #fff; color: #222;
  transition: border-color .18s, box-shadow .18s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,.15); }
.form-control[readonly], .form-control.auto-field {
  background: #f3f4f6; color: #6b7280; cursor: default;
}
textarea.form-control { min-height: 90px; resize: vertical; }
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-actions { display: flex; gap: 10px; padding-top: 8px; flex-wrap: wrap; }

/* ---- Tables ---- */
.table-responsive { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: .85rem;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.data-table th {
  background: #f8fafc; font-weight: 600;
  color: #374151; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .4px;
  position: sticky; top: 0; z-index: 1;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table .actions { display: flex; gap: 4px; }
.table-empty { text-align: center; padding: 40px; color: #94a3b8; font-size: .9rem; }

/* ---- Badges / Status ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; font-size: .75rem; font-weight: 600;
  border-radius: 12px;
  white-space: nowrap;
}
.badge-open { background: var(--primary-light); color: var(--primary); }
.badge-inprogress { background: #fef3c7; color: #d97706; }
.badge-delayed { background: var(--danger-light); color: var(--danger); }
.badge-closed { background: var(--success-light); color: #155724; }
.badge-high { background: var(--danger-light); color: var(--danger); }
.badge-medium { background: var(--warning-light); color: #856404; }
.badge-low { background: var(--success-light); color: #155724; }
.badge-filled { background: var(--success-light); color: var(--success); }
.badge-pending { background: #f3f4f6; color: #6b7280; }

/* ---- Modal ---- */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 500;
  justify-content: center; align-items: flex-start;
  padding: 30px 16px; overflow-y: auto;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 720px; margin: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 700; color: #1e293b; }
.modal-close {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: #94a3b8; line-height: 1;
}
.modal-close:hover { color: #333; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal-lg { max-width: 900px; }
.modal-sm { max-width: 480px; }

/* ---- Charts ---- */
.chart-container { position: relative; height: 280px; }
.charts-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-bottom: 20px; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding: 12px 0; }
.page-btn {
  padding: 6px 12px; font-size: .82rem; border-radius: 6px;
  border: 1px solid var(--border); background: #fff;
  cursor: pointer; color: #374151; transition: all .15s;
}
.page-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-info { font-size: .82rem; color: #64748b; margin-left: 8px; }

/* ---- Notifications ---- */
.notif-list .notif-item {
  display: flex; gap: 12px; padding: 14px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: var(--primary-light); }
.notif-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .9rem; flex-shrink: 0; }
.notif-icon.high { background: var(--danger-light); color: var(--danger); }
.notif-icon.medium { background: var(--warning-light); color: var(--warning); }
.notif-icon.low { background: var(--success-light); color: var(--success); }
.notif-body { flex: 1; }
.notif-title { font-weight: 600; font-size: .88rem; color: #1e293b; }
.notif-msg { font-size: .82rem; color: #64748b; margin-top: 2px; }
.notif-date { font-size: .75rem; color: #94a3b8; margin-top: 4px; }

/* ---- Alert / Toast ---- */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: .88rem; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.alert-success { background: var(--success-light); color: #155724; border: 1px solid #c3e6cb; }
.alert-danger { background: var(--danger-light); color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: var(--warning-light); color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: var(--primary-light); color: #004085; border: 1px solid #bee5eb; }

.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary);
  min-width: 280px; max-width: 380px;
  animation: slideIn .3s ease;
  font-size: .88rem;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- Login Page ---- */
.login-page {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: #fff; border-radius: 12px;
  padding: 36px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 1.3rem; font-weight: 700; color: #1e293b; margin-top: 10px; }
.login-logo p { font-size: .82rem; color: #64748b; margin-top: 4px; }

/* ---- Dashboard ---- */
.quick-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.quick-link {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 14px 8px; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; color: #334155;
  font-size: .82rem; font-weight: 500;
  transition: all .18s;
  box-shadow: var(--shadow);
}
.quick-link:hover { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.quick-link .ql-icon { font-size: 1.4rem; }

/* ---- Reports ---- */
.report-header { background: var(--primary); color: #fff; border-radius: var(--radius) var(--radius) 0 0; padding: 20px 24px; }
.report-header h2 { font-size: 1.2rem; font-weight: 700; }
.report-header .meta { font-size: .82rem; opacity: .85; margin-top: 6px; }

/* ---- Misc ---- */
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.text-muted { color: #94a3b8; font-size: .82rem; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }
.d-flex { display: flex; } .align-center { align-items: center; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.flex-1 { flex: 1; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ---- Flatpickr overrides ---- */
.flatpickr-calendar { font-family: inherit; box-shadow: var(--shadow-md); border-radius: var(--radius); }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--primary); border-color: var(--primary); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .header { left: 0; }
  .main-content { margin-left: 0; padding: 16px; }
  .header .hamburger { display: block; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block; width: 100%;
  }
  .data-table tr {
    background: #fff; margin-bottom: 10px;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px; box-shadow: var(--shadow);
  }
  .data-table td {
    padding: 6px 10px; border: none;
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 6px;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600; font-size: .78rem; color: #64748b;
    text-transform: uppercase; letter-spacing: .4px;
    min-width: 120px;
  }
  .data-table td.no-label::before { display: none; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .charts-row { grid-template-columns: 1fr; }
  .btn { width: 100%; justify-content: center; }
  .btn-sm, .btn-xs { width: auto; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filters-grid { grid-template-columns: 1fr; }
  .quick-links { grid-template-columns: repeat(3,1fr); }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .quick-links { grid-template-columns: repeat(2,1fr); }
  .modal { margin: 0; border-radius: 0; max-width: 100%; }
  .modal-backdrop { padding: 0; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
}

/* ---- Print ---- */
@media print {
  .sidebar, .header, .filters-bar, .btn, .modal-backdrop { display: none !important; }
  .main-content { margin: 0; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
