/* Professional Modern UI for ABF AUTO */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

:root {
  /* Core Colors - Premium Enterprise Palette */
  --bg-main: #020617;
  --bg-sidebar: #0a0f1d;
  --bg-card: #0f172a;
  --bg-card-hover: #1e293b;
  --bg-input: #0f172a;
  
  --border-color: rgba(148, 163, 184, 0.15);
  --border-color-focus: rgba(16, 185, 129, 0.5);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-inverse: #020617;
  
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  
  --secondary: #6366f1;
  --secondary-hover: #4f46e5;
  
  --error: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;

  /* Typography */
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', var(--font-main);
  
  /* Layout & Spacing */
  --sidebar-width: 260px;
  --header-height: 72px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  /* Shadows & Glassmorphism */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --glass-bg: rgba(15, 23, 42, 0.8);
  --glass-border: rgba(255, 255, 255, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  margin: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--primary-hover);
}

/* Auth Pages */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1e293b, #020617);
  overflow: hidden;
}

.auth-video-bg {
  position: relative;
}

.auth-bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.1) contrast(1.1) brightness(0.7);
  transform: scale(1.05);
  z-index: 0;
}

.auth-bg-overlay {
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(1200px 600px at 20% 20%, rgba(16, 185, 129, 0.15), transparent 60%),
    radial-gradient(900px 500px at 80% 30%, rgba(99, 102, 241, 0.12), transparent 55%),
    linear-gradient(to bottom, rgba(2, 6, 23, 0.6), rgba(2, 6, 23, 0.95));
  z-index: 1;
}

.auth-container {
  position: relative;
  z-index: 10;
  padding: 1.5rem;
  width: 100%;
  max-width: 440px;
}

.auth-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-xl);
  padding: 3rem 2.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--glass-border);
}

.auth-title {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-title {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--primary);
  margin-bottom: 2rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-form label span {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.auth-form input {
  background: rgba(2, 6, 23, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  color: white;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.auth-form input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  gap: 0.5rem;
}

.primary-btn {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}

.primary-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3);
}

.primary-btn:active {
  transform: translateY(0);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.2);
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand-wrapper {
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
}

.sidebar-brand {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.2s ease;
}

.sidebar-link i {
  width: 20px;
  height: 20px;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: white;
}

.sidebar-link.active {
  background: rgba(16, 185, 129, 0.1);
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Main Content Area */
.main {
  padding: 2.5rem 3rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
}

.main-title {
  font-size: 1.75rem;
  font-family: var(--font-heading);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
}

.badge-role {
  background: rgba(16, 185, 129, 0.1);
  color: var(--primary);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Cards & Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-lg);
}

.card-title {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-stat {
  font-size: 2rem;
  font-family: var(--font-heading);
  font-weight: 700;
  color: white;
}

.card-sub {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Tables */
.table-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  background: rgba(255, 255, 255, 0.02);
  padding: 1rem 1.5rem;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.table td {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Tags & Indicators */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag-success {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
}

.tag-muted {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-field input, .form-field select, .form-field textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: white;
  font-family: inherit;
  transition: all 0.2s ease;
}

.form-field input:focus, .form-field select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Alerts */
.alert {
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-warning {
  background: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.main > * {
  animation: fadeIn 0.4s ease-out forwards;
}

/* =============================================
   RESPONSIVE — TABLET (769px – 1024px)
   Icon-only sidebar
   ============================================= */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 80px;
  }
  .sidebar-header,
  .sidebar-brand,
  .sidebar-link span,
  .sidebar-footer,
  .sidebar-close-btn {
    display: none;
  }
  .sidebar-link {
    justify-content: center;
    padding: 1rem;
  }
}

/* =============================================
   RESPONSIVE — MOBILE (≤ 768px)
   Slide-in overlay sidebar + hamburger header
   ============================================= */
@media (max-width: 768px) {

  /* --- App Shell --- */
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* --- Sidebar: hidden off-screen by default --- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    height: 100vh;
    flex-direction: column;
    padding: 1.5rem 1rem;
    z-index: 500;
    border-right: 1px solid var(--border-color);
    border-top: none;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    gap: 1.5rem;
  }

  /* When sidebar-open class on app-shell, slide in */
  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
  }

  /* Show sidebar text labels + close button on mobile overlay */
  .sidebar-header,
  .sidebar-brand,
  .sidebar-link span,
  .sidebar-footer {
    display: unset;
  }

  .sidebar-link {
    justify-content: flex-start;
    padding: 0.75rem 1rem;
  }

  /* --- Close button inside sidebar (mobile only) --- */
  .sidebar-close-btn {
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
  }

  .sidebar-close-btn button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
  }

  .sidebar-close-btn button:hover {
    color: white;
    background: rgba(255,255,255,0.05);
  }

  /* --- Backdrop overlay --- */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 499;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
  }

  /* --- Main content: full width, sticky top header --- */
  .main {
    padding: 0;
    max-width: 100%;
    margin: 0;
    width: 100%;
  }

  .main-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    padding: 0.875rem 1rem;
    margin-bottom: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* --- Hamburger button in header (mobile only) --- */
  .hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 0.45rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
  }

  .hamburger-btn:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.2);
  }

  .hamburger-btn svg {
    width: 22px;
    height: 22px;
  }

  /* --- Header title: smaller on mobile --- */
  .main-title {
    font-size: 1.2rem;
    flex: 1;
  }

  /* --- User badge: compact on mobile --- */
  .user-badge {
    padding: 0.4rem 0.4rem 0.4rem 0.75rem;
    gap: 0.5rem;
  }

  /* Hide name/role text, keep only logout button */
  .user-badge > i,
  .user-badge > div {
    display: none;
  }

  /* Page content padding for mobile */
  .page-content {
    padding: 1rem;
  }

  /* --- Alerts --- */
  .alert {
    margin-bottom: 1rem;
    font-size: 0.8125rem;
  }

  /* --- Cards grid: single column on mobile --- */
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 0.875rem;
    margin-bottom: 1.5rem;
  }

  /* --- Tables: horizontal scroll on mobile --- */
  .table-container,
  .table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Bare tables not wrapped in .table-container get a scroll wrapper */
  section > .table,
  .card > .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .table th,
  .table td {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    white-space: nowrap;
  }

  /* --- Sale-line table: card layout on mobile --- */
  #sale-lines thead {
    display: none;
  }

  #sale-lines tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 0;
    white-space: normal;
  }

  #sale-lines tbody tr td {
    display: block;
    padding: 0.25rem 0;
    white-space: normal;
    border: none;
  }

  /* Item select spans full width */
  #sale-lines tbody tr td:first-child {
    grid-column: 1 / -1;
  }

  /* Remove button aligned right */
  #sale-lines tbody tr td:last-child {
    grid-column: 2;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
  }

  /* --- Form actions --- */
  .form-actions {
    flex-direction: column;
    gap: 0.75rem;
  }

  .form-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* --- Form grid: single column --- */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Inputs & selects: ensure min touch target */
  .form-field input,
  .form-field select,
  .form-field textarea {
    font-size: 1rem; /* Prevents iOS auto-zoom */
    min-height: 44px;
  }

  .auth-form input {
    font-size: 1rem;
  }

  /* --- Auth page: reduced padding on small screens --- */
  .auth-card {
    padding: 2rem 1.5rem;
  }

  .auth-title {
    font-size: 1.6rem;
  }

  /* Hint text in sales/branch sections */
  section > h2 {
    font-size: 0.9375rem;
    margin-bottom: 0.5rem;
  }
}

/* Extra small screens */
@media (max-width: 380px) {
  .auth-card {
    padding: 1.5rem 1rem;
  }
  .main-title {
    font-size: 1rem;
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 769px) {
  .hamburger-btn {
    display: none !important;
  }
  .sidebar-close-btn {
    display: none !important;
  }
  .sidebar-backdrop {
    display: none !important;
  }
}
