/* ============================================================
   TCMS - Transport Cooperative Management System
   Main Stylesheet
   ============================================================ */

:root {
  --primary:        #1a56db;
  --primary-dark:   #1341a8;
  --primary-light:  #e8f0fe;
  --accent:         #0ea5e9;
  --success:        #16a34a;
  --warning:        #d97706;
  --danger:         #dc2626;
  --info:           #0891b2;

  --sidebar-w:      260px;
  --topbar-h:       64px;

  --bg:             #f0f4f8;
  --card-bg:        #ffffff;
  --border:         #e2e8f0;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  --shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:         0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:      0 10px 40px rgba(0,0,0,.12);

  --radius:         12px;
  --radius-sm:      8px;
  --radius-lg:      16px;

  --font:           'Plus Jakarta Sans', sans-serif;
  --font-mono:      'JetBrains Mono', monospace;

  --transition:     all .2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: var(--transition);
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-icon {
  width: 42px; height: 42px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  color: #fff;
  flex-shrink: 0;
}

.brand-title {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: .5px;
  display: block;
  line-height: 1;
}

.brand-sub {
  font-size: .68rem;
  color: rgba(255,255,255,.4);
  display: block;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.nav-section-label {
  font-size: .6rem;
  font-weight: 700;
  color: rgba(255,255,255,.25);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 12px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: 2px;
  transition: var(--transition);
}

.nav-item i { font-size: 1rem; width: 20px; flex-shrink: 0; }

.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(26,86,219,.4);
}

.logout-item:hover { background: rgba(220,38,38,.15); color: #f87171; }

/* ===== MAIN WRAPPER ===== */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

/* ===== TOPBAR ===== */
.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 900;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }

.sidebar-toggle {
  background: none; border: 1px solid var(--border);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: var(--text-muted);
  cursor: pointer; transition: var(--transition);
}
.sidebar-toggle:hover { background: var(--bg); }

.page-breadcrumb { display: flex; align-items: center; font-size: .8rem; }
.coop-label { color: var(--text-muted); font-weight: 500; }
.page-name { color: var(--text); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.topbar-date {
  display: flex; align-items: center; gap: 6px;
  font-size: .8rem; color: var(--text-muted);
  background: var(--bg); padding: 6px 12px; border-radius: 20px;
}

.admin-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 20px;
  font-size: .8rem; font-weight: 600; color: var(--text);
  cursor: pointer; transition: var(--transition);
}
.admin-pill:hover { border-color: var(--primary); }

.admin-avatar {
  width: 28px; height: 28px;
  background: var(--primary); color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; flex-shrink: 0;
}

.admin-dropdown { min-width: 220px; }

/* ===== PAGE CONTENT ===== */
.page-content {
  flex: 1;
  padding: 24px;
}

/* ===== STAT CARDS ===== */
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  height: 100%;
}

.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.indigo  { background: #e0e7ff; color: #4338ca; }
.stat-icon.pink    { background: #fce7f3; color: #be185d; }
.stat-icon.brown   { background: #fef3c7; color: #92400e; }

.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-icon.teal   { background: #cffafe; color: var(--info); }

.stat-info { flex: 1; min-width: 0; }
.stat-label {
  font-size: .72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px;
}
.stat-value {
  font-size: 1.5rem; font-weight: 800; color: var(--text); line-height: 1.1;
}
.stat-sub { font-size: .72rem; color: var(--text-light); margin-top: 2px; }

/* ===== CARDS ===== */
.tcms-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.tcms-card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
}

.tcms-card-title {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tcms-card-title i { color: var(--primary); }

.tcms-card-body { padding: 20px; }

/* ===== TABLES ===== */
.table { font-size: .84rem; }
.table thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  white-space: nowrap;
}
.table tbody td { padding: 10px 14px; vertical-align: middle; }
.table tbody tr:hover { background: #f8fafc; }

/* ===== BADGES ===== */
.badge-paid     { background: #dcfce7; color: #15803d; }
.badge-unpaid   { background: #fee2e2; color: #b91c1c; }
.badge-active   { background: #dbeafe; color: #1d4ed8; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-fullpaid { background: #dcfce7; color: #15803d; }
.badge-diesel   { background: #fef9c3; color: #854d0e; }
.badge-gasoline { background: #e0f2fe; color: #0369a1; }

.status-badge {
  padding: 3px 10px; border-radius: 20px; font-size: .72rem; font-weight: 600;
}

/* ===== BUTTONS ===== */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: .85rem;
}

/* ===== ACTIVITY LOG ===== */
.activity-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }

.activity-icon {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; flex-shrink: 0;
}

.activity-text { flex: 1; }
.activity-action { font-weight: 600; font-size: .82rem; color: var(--text); }
.activity-time { font-size: .72rem; color: var(--text-light); }

/* ===== FORMS ===== */
.form-label { font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.form-control, .form-select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .875rem; padding: 8px 12px;
  transition: var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

/* ===== MODALS ===== */
.modal-header {
  background: var(--primary); color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
}
.modal-title { font-weight: 700; font-size: .95rem; }
.btn-close-white { filter: invert(1); }

/* ===== PAGE TITLE ===== */
.page-title-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title { font-size: 1.25rem; font-weight: 800; color: var(--text); }
.page-title-sub { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* ===== LOGIN PAGE ===== */
.login-body {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1a56db 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  width: 60px; height: 60px;
  background: var(--primary); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; color: #fff; margin: 0 auto 16px;
}

.login-title { font-size: 1.3rem; font-weight: 800; color: var(--text); }
.login-sub { font-size: .82rem; color: var(--text-muted); }

/* ===== RESPONSIVE ===== */
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-section-label { display: none; }
.sidebar.collapsed .brand-icon { margin: 0 auto; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-item i { width: auto; }
.main-wrapper.expanded { margin-left: 68px; }

@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 999; display: none;
  }
  .sidebar-backdrop.show { display: block; }
}

@media (max-width: 576px) {
  .page-content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .stat-value { font-size: 1.2rem; }
}

/* ===== CHARTS ===== */
.chart-container { position: relative; height: 240px; }

/* ===== MISC ===== */
.mono { font-family: var(--font-mono); }
.text-peso { color: var(--success); font-weight: 700; }
.divider-text {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-light); font-size: .75rem;
}
.divider-text::before, .divider-text::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* DataTables overrides */
.dataTables_wrapper .dataTables_filter input { border-radius: var(--radius-sm); border: 1px solid var(--border); padding: 5px 10px; font-size: .82rem; }
.dataTables_wrapper .dataTables_length select { border-radius: var(--radius-sm); border: 1px solid var(--border); padding: 4px 8px; font-size: .82rem; }
.dataTables_wrapper .dataTables_info { font-size: .78rem; color: var(--text-muted); }
.paginate_button { border-radius: var(--radius-sm) !important; font-size: .78rem !important; }

/* Summary Strip */
.summary-strip {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.summary-item { display: flex; flex-direction: column; }
.summary-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-light); }
.summary-val { font-size: .95rem; font-weight: 800; }

/* ============================================================
   RESPONSIVE OVERHAUL — Mobile-first fixes
   ============================================================ */

/* ── Tablet (≤992px): sidebar off-canvas ─────────────────── */
@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    z-index: 1050;
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.3); }
  .main-wrapper { margin-left: 0 !important; }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 1040; display: none;
  }
  .sidebar-backdrop.show { display: block; }

  /* Topbar */
  .topbar-date { display: none; }
  .page-breadcrumb .coop-label { display: none; }

  /* Cards */
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-icon { width: 42px; height: 42px; font-size: 1.1rem; }
  .stat-value { font-size: 1.2rem; }

  /* Tables */
  .table { font-size: .8rem; }
  .table thead th { font-size: .68rem; padding: 8px 10px; }
  .table tbody td { padding: 8px 10px; }

  /* Filter bars */
  .tcms-card-header { flex-direction: column; align-items: flex-start !important; }
  .tcms-card-header > div:last-child { width: 100%; }
  .tcms-card-header form { width: 100%; }
  .tcms-card-header form input,
  .tcms-card-header form select { width: 100% !important; flex: 1 1 140px; }

  /* Report sidebar */
  .col-lg-3.col-lg-9 { flex: 0 0 100%; max-width: 100%; }

  /* Modals full-width */
  .modal-dialog { margin: 8px; }
  .modal-dialog.modal-lg { max-width: calc(100vw - 16px); }
}

/* ── Mobile (≤576px): full mobile design ────────────────── */
@media (max-width: 576px) {
  /* Base */
  html { font-size: 13px; }
  body { font-size: 13px; }

  /* Layout */
  .page-content { padding: 12px; }
  .topbar { padding: 0 12px; height: 54px; }
  --topbar-h: 54px;

  /* Page title bar */
  .page-title-bar { flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
  .page-title { font-size: 1rem; }
  .page-title-sub { font-size: .72rem; }
  .page-title-bar > div:last-child { width: 100%; }
  .page-title-bar .btn { width: 100%; justify-content: center; }

  /* Stat cards */
  .stat-card { padding: 10px; gap: 8px; border-radius: 8px; }
  .stat-icon { width: 36px; height: 36px; font-size: .95rem; border-radius: 8px; }
  .stat-label { font-size: .62rem; }
  .stat-value { font-size: 1.1rem; }
  .stat-sub { display: none; }

  /* Cards */
  .tcms-card { border-radius: 8px; }
  .tcms-card-header { padding: 12px 14px; gap: 8px; }
  .tcms-card-title { font-size: .82rem; }
  .tcms-card-body { padding: 14px; }

  /* Tables — horizontal scroll with sticky first col */
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .table { font-size: .76rem; min-width: 520px; }
  .table thead th { font-size: .64rem; padding: 7px 8px; white-space: nowrap; }
  .table tbody td { padding: 7px 8px; white-space: nowrap; }

  /* Filter bars stack */
  .tcms-card-header form { flex-direction: column; }
  .tcms-card-header form input,
  .tcms-card-header form select,
  .tcms-card-header form button,
  .tcms-card-header form a { width: 100% !important; }
  .tcms-card-header > div { flex-direction: column; width: 100%; }

  /* Topbar elements */
  .admin-name { display: none !important; }
  .topbar-date { display: none; }
  .admin-pill { padding: 5px 8px; }
  .admin-avatar { width: 26px; height: 26px; font-size: .7rem; }

  /* Sidebar toggle */
  .sidebar-toggle { width: 34px; height: 34px; font-size: 1.1rem; }

  /* Modals */
  .modal-dialog { margin: 6px; max-width: calc(100vw - 12px) !important; }
  .modal-header { padding: 12px 14px; }
  .modal-title { font-size: .88rem; }
  .modal-body { padding: 14px; }
  .modal-footer { padding: 10px 14px; flex-wrap: wrap; gap: 6px; }
  .modal-footer .btn { flex: 1 1 calc(50% - 6px); font-size: .82rem; padding: 7px; }

  /* Forms */
  .form-label { font-size: .78rem; margin-bottom: 3px; }
  .form-control, .form-select { font-size: .84rem; padding: 7px 10px; }
  .input-group-text { font-size: .84rem; padding: 7px 10px; }

  /* Buttons */
  .btn-sm { font-size: .78rem; padding: 5px 10px; }
  .btn-icon { width: 28px; height: 28px; font-size: .78rem; }

  /* Charts */
  .chart-container { height: 180px; }

  /* DataTables controls */
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length { width: 100%; }
  .dataTables_wrapper .dataTables_filter input { width: 100% !important; }
  div.dataTables_wrapper div.dataTables_paginate { text-align: center; }

  /* Badges */
  .status-badge { font-size: .65rem; padding: 2px 7px; }
  .badge { font-size: .65rem; }

  /* Summary strip */
  .summary-strip { gap: 10px; padding: 10px 14px; }

  /* Report page special */
  .col-lg-3 { margin-bottom: 12px; }

  /* Login page */
  .login-card { padding: 24px 18px; }
  .login-logo { width: 52px; height: 52px; font-size: 1.5rem; }
  .login-title { font-size: 1.1rem; }
}

/* ── Extra small (≤400px): very small phones ────────────── */
@media (max-width: 400px) {
  html { font-size: 12px; }
  .page-content { padding: 10px; }
  .stat-value { font-size: 1rem; }
  .stat-icon { width: 32px; height: 32px; font-size: .85rem; }
  .col-6 { padding-left: 5px; padding-right: 5px; }
  .row { --bs-gutter-x: 0.5rem; }
  .page-title { font-size: .95rem; }
}

/* ── Utility: hide on mobile ─────────────────────────────── */
@media (max-width: 576px) {
  .hide-mobile { display: none !important; }
  .mono { letter-spacing: 0; }
}

/* ── Touch-friendly tap targets ──────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .nav-item { padding: 12px 12px; min-height: 44px; }
  .btn { min-height: 38px; }
  .btn-icon { min-height: 36px; min-width: 36px; }
  .form-control, .form-select { min-height: 42px; }
}
