/* File: /assets/css/app.css
   Responsive desktop, tablet and mobile application stylesheet.
*/
:root {
  color-scheme: light;
  --emerald: #059669;
  --emerald-dark: #047857;
  --emerald-light: #ecfdf5;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --input-border: #d1d5db;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0284c7;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(17, 24, 39, .05);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --emerald: #10b981;
  --emerald-dark: #34d399;
  --emerald-light: rgba(16, 185, 129, .14);
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1f2937;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: #374151;
  --input-border: #4b5563;
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #38bdf8;
  --shadow: 0 4px 18px rgba(0, 0, 0, .28);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; width: 100%; }
body {
  min-height: 100vh;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color .2s ease, color .2s ease;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
img, svg, video { max-width: 100%; }

/* Authentication */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(100%, 420px); padding: 24px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-badge {
  width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center;
  border-radius: 10px; background: var(--emerald); color: #fff; font-size: 19px; font-weight: 800;
}
.auth-brand h1 { margin: 0; font-size: 18px; }
.auth-brand p, .auth-hint { color: var(--muted); font-size: 13px; }
.auth-brand p { margin: 2px 0 0; }
.auth-hint { margin-top: 14px; text-align: center; font-size: 12px; }

/* Main application layout */
.app-shell { display: flex; min-height: 100vh; width: 100%; }
.sidebar {
  width: 250px; flex: 0 0 250px; min-height: 100vh; padding: 20px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; margin: 0 0 24px;
  padding: 0 8px; font-weight: 800; color: var(--emerald-dark);
}
.nav-list { display: grid; gap: 5px; list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: flex; align-items: center; min-height: 42px; gap: 10px; padding: 10px 12px;
  border-radius: 9px; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav-link:hover, .nav-link.active { background: var(--emerald-light); color: var(--emerald-dark); font-weight: 700; }
.nav-logout { margin-top: 8px; color: var(--danger); }
.nav-logout:hover { color: var(--danger); background: rgba(220, 38, 38, .08); }

.main-area { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; width: calc(100% - 250px); }
.topbar {
  position: sticky; top: 0; z-index: 30; min-height: 62px; width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; min-width: 0; flex: 1 1 auto; }
.topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 0 0 auto; }
.icon-btn, .mobile-menu-btn {
  width: 38px; height: 38px; flex: 0 0 38px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-alt);
  color: var(--text); cursor: pointer;
}
.icon-btn { font-size: 17px; }
.icon-btn:hover, .mobile-menu-btn:hover { background: var(--emerald-light); border-color: var(--emerald); color: var(--emerald-dark); }
.mobile-menu-btn { display: none; font-size: 19px; }
.content { width: 100%; max-width: 1500px; min-width: 0; margin: 0 auto; padding: 22px; padding-bottom: 36px; }

/* Status badges */
.sync-badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.sync-synced { background: #d1fae5; color: #065f46; }
.sync-offline { background: #e5e7eb; color: #374151; }
.sync-pending { background: #fef3c7; color: #92400e; }
.sync-synchronizing { background: #e0f2fe; color: #075985; }
.sync-failed, .sync-conflict { background: #fee2e2; color: #991b1b; }
:root[data-theme="dark"] .sync-synced { background: rgba(16,185,129,.2); color: #6ee7b7; }
:root[data-theme="dark"] .sync-offline { background: rgba(156,163,175,.2); color: #d1d5db; }
:root[data-theme="dark"] .sync-pending { background: rgba(245,158,11,.2); color: #fcd34d; }
:root[data-theme="dark"] .sync-synchronizing { background: rgba(56,189,248,.2); color: #7dd3fc; }
:root[data-theme="dark"] .sync-failed, :root[data-theme="dark"] .sync-conflict { background: rgba(248,113,113,.2); color: #fca5a5; }

/* Cards and dashboard metrics */
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  min-width: 0; padding: 18px; margin-bottom: 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card h2, .card h3 { margin: 0 0 14px; font-size: 16px; line-height: 1.35; }
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .045em; }
.kpi-value { margin-top: 6px; color: var(--text); font-size: clamp(19px, 2vw, 27px); font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.kpi-sub { margin-top: 7px; color: var(--emerald-dark); font-size: 12px; }

/* Forms and buttons */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 700; }
.form-control {
  display: block; width: 100%; min-height: 42px; padding: 10px 12px;
  border: 1px solid var(--input-border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px;
}
.form-control:focus { outline: none; border-color: var(--emerald); box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px;
  font-size: 14px; font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--emerald); color: #fff; }
.btn-primary:hover { background: var(--emerald-dark); color: #fff; }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--input-border); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-sm { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* Tables: retain readable columns and scroll inside their own wrapper */
.table-wrap { width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; border-radius: 8px; }
table { width: 100%; min-width: 650px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: var(--surface-alt); color: var(--text); font-weight: 800; }
tbody tr:hover { background: var(--surface-alt); }

/* Alerts */
.alert { padding: 12px 14px; margin-bottom: 16px; border: 1px solid transparent; border-radius: 9px; font-size: 13px; overflow-wrap: anywhere; }
.alert a { color: inherit; font-weight: 800; }
.alert-danger { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
:root[data-theme="dark"] .alert-danger { background: rgba(220,38,38,.15); color: #fecaca; border-color: rgba(248,113,113,.3); }
:root[data-theme="dark"] .alert-success { background: rgba(16,185,129,.15); color: #a7f3d0; border-color: rgba(16,185,129,.3); }

/* Mobile navigation drawer */
.mobile-drawer-backdrop { display: none; position: fixed; inset: 0; z-index: 40; background: rgba(15,23,42,.55); }
.mobile-drawer-backdrop.open { display: block; }
.mobile-drawer {
  position: fixed; z-index: 50; top: 0; right: 0; bottom: 0; width: 290px; max-width: min(86vw, 360px);
  padding: 18px 16px; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(15,23,42,.18); transform: translateX(105%); visibility: hidden;
  transition: transform .24s cubic-bezier(.22,1,.36,1), visibility .24s ease;
}
.mobile-drawer.open { transform: translateX(0); visibility: visible; }
.mobile-drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.drawer-user { font-size: 14px; font-weight: 800; overflow-wrap: anywhere; }
.drawer-sub { color: var(--muted); font-size: 12px; }

/* Tablet */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .content { padding: 18px; }
}

/* Mobile and small tablets */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main-area { width: 100%; }
  .mobile-menu-btn { display: inline-flex; }
  .topbar { min-height: 58px; padding: 9px 12px; gap: 8px; }
  .topbar-title { font-size: 15px; }
  .topbar-right { gap: 6px; }
  .content { padding: 14px; padding-bottom: 28px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 14px; margin-bottom: 14px; }
  .kpi-value { font-size: clamp(18px, 4vw, 23px); }
}
@media (max-width: 480px) {
  .topbar { align-items: center; }
  .topbar-title { font-size: 14px; }
  .topbar-right { gap: 5px; }
  .topbar-right .sync-badge { max-width: 84px; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right .btn { padding: 6px 8px; }
  .content { padding: 11px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 12px; border-radius: 10px; }
  .kpi-label { font-size: 10px; }
  .kpi-value { font-size: 18px; }
  .kpi-sub { font-size: 11px; }
  .card h2, .card h3 { font-size: 15px; }
  .auth-card { padding: 20px; }
}
@media (max-width: 350px) {
  .topbar-title { max-width: 110px; }
  .topbar-right .sync-badge { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
}


/* =========================================================
   RESPONSIVE NAVIGATION FIX
   High-specificity rules prevent the drawer appearing in
   the normal page flow and hide the hamburger on desktop.
   ========================================================= */
html body .app-shell > .main-area { min-width: 0; }

html body .app-shell > .main-area > .mobile-drawer,
html body .mobile-drawer {
  display: block !important;
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: auto !important;
  width: 290px !important;
  max-width: min(86vw, 360px) !important;
  height: 100vh !important;
  height: 100dvh !important;
  margin: 0 !important;
  padding: 18px 16px !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  background: var(--surface) !important;
  border: 0 !important;
  border-left: 1px solid var(--border) !important;
  box-shadow: -8px 0 28px rgba(15, 23, 42, .18) !important;
  z-index: 1001 !important;
  transform: translate3d(105%, 0, 0) !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transition: transform .24s ease, opacity .24s ease, visibility .24s ease !important;
}

html body .app-shell > .main-area > .mobile-drawer.open,
html body .mobile-drawer.open {
  transform: translate3d(0, 0, 0) !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

html body .mobile-drawer .nav-list {
  display: grid !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  list-style: none !important;
}

html body .mobile-drawer .nav-list li { display: block !important; width: 100% !important; }
html body .mobile-drawer .nav-link { display: flex !important; width: 100% !important; }

html body .mobile-drawer-backdrop {
  display: block !important;
  position: fixed !important;
  inset: 0 !important;
  z-index: 1000 !important;
  background: rgba(15, 23, 42, .55) !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition: opacity .2s ease, visibility .2s ease !important;
}

html body .mobile-drawer-backdrop.open {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

html body .mobile-menu-btn { display: none !important; }

@media (max-width: 860px) {
  html body .app-shell > .sidebar { display: none !important; }
  html body .app-shell > .main-area { width: 100% !important; }
  html body .mobile-menu-btn { display: inline-flex !important; }
  html body .topbar { width: 100% !important; }
}

@media (min-width: 861px) {
  html body .mobile-menu-btn { display: none !important; }
  html body .mobile-drawer,
  html body .mobile-drawer-backdrop { display: none !important; }
}

