/* public/css/app.css - Diraa Petroleum Modern Responsive Stylesheet */

:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --primary-dark: #075985;
  
  --petrol-blue: #2563eb;
  --diesel-green: #16a34a;
  --speed-red: #dc2626;

  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-header: #ffffff;
  --bg-sidebar: #0f172a;
  --border-color: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --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);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  overflow-x: hidden;
  max-width: 100%;
  width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

img, svg, video, canvas, audio, iframe, embed, object {
  display: inline-block;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

p, h1, h2, h3, h4, h5, h6, span, div, a, label {
  overflow-wrap: break-word;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* App Shell Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
}

/* Sidebar for Desktop & Tablets */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 40;
}

.sidebar-header {
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-img {
  height: 40px;
  width: auto;
  max-width: 170px;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-grow: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #94a3b8;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: all 0.15s ease;
  min-height: 44px;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  text-decoration: none;
}

.nav-item.active {
  background-color: var(--primary);
  color: #ffffff;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background-color: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  background-color: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.user-info {
  flex-grow: 1;
  overflow: hidden;
  min-width: 0;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Sidebar Backdrop on Mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 98;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
}

/* Main Content Area */
.main-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  overflow-x: hidden;
  background-color: var(--bg-main);
  padding-bottom: calc(72px + var(--safe-bottom)); /* Space for mobile bottom nav */
}

@media (min-width: 769px) {
  .main-wrapper {
    padding-bottom: 24px;
  }
}

/* Top App Bar */
.topbar {
  height: 64px;
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 30;
  width: 100%;
  max-width: 100%;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  min-height: 44px;
  min-width: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background-color: #f1f5f9;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border-color);
  width: 40px;
  height: 40px;
  min-height: 40px;
  min-width: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s;
}

.icon-btn:hover {
  background-color: var(--border-color);
}

.badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  background-color: var(--danger);
  border-radius: 50%;
  border: 2px solid #ffffff;
}

/* Content Container */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  min-width: 0;
}

/* Flash Messages */
.flash-alert {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  word-break: break-word;
}

.flash-success { background-color: var(--success-bg); color: var(--success); }
.flash-danger { background-color: var(--danger-bg); color: var(--danger); }
.flash-info { background-color: var(--info-bg); color: var(--info); }
.flash-warning { background-color: var(--warning-bg); color: var(--warning); }

/* Offline Status Banner */
.offline-banner {
  display: none;
  background-color: #ef4444;
  color: #ffffff;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 50;
}

.offline-banner.active {
  display: block;
}

/* Card Component */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 20px;
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 10px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  word-break: break-word;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  max-width: 100%;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
  border-color: var(--success);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background-color: var(--bg-main);
}

.btn-block {
  width: 100%;
  display: flex;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 16px;
  min-height: 52px;
  border-radius: var(--radius-md);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background-color: var(--success-bg); color: var(--success); }
.badge-danger { background-color: var(--danger-bg); color: var(--danger); }
.badge-warning { background-color: var(--warning-bg); color: var(--warning); }
.badge-info { background-color: var(--info-bg); color: var(--info); }
.badge-neutral { background-color: #f1f5f9; color: #475569; }

/* Responsive Header Actions Helper */
.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Grid Systems */
.grid {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Metric / KPI Stat Card */
.metric-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.metric-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  word-break: break-word;
}

.metric-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Forms */
.form-group {
  margin-bottom: 16px;
  min-width: 0;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  max-width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: #ffffff;
  color: var(--text-main);
  outline: none;
  min-height: 44px;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* Large Input for Touch Keypad & Meters */
.input-large {
  font-size: 24px !important;
  font-weight: 800 !important;
  text-align: center;
  letter-spacing: 1px;
  padding: 12px 16px !important;
  min-height: 58px !important;
  background-color: #f8fafc;
}

/* Tables & Horizontal Touch Scrolling */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: block;
  position: relative;
}

.table-responsive::-webkit-scrollbar {
  height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.data-table th {
  background-color: #f8fafc;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td.wrap, .data-table th.wrap {
  white-space: normal;
}

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

.data-table tr:hover {
  background-color: #f1f5f9;
}

/* Tank Stock Progress Gauge */
.stock-gauge-wrapper {
  margin-top: 10px;
}

.stock-gauge-bar {
  height: 12px;
  background-color: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.stock-gauge-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #38bdf8);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* Modals & Dialog Overlays */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay .card {
  max-width: 600px;
  width: 100%;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  margin: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  justify-content: space-around;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-md);
  position: relative;
  min-height: 44px;
  justify-content: center;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item svg {
  width: 22px;
  height: 22px;
}

/* Sequential Mobile Wizard Steps */
.wizard-container {
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  overflow-x: hidden;
  position: relative;
}

.wizard-header {
  padding: 16px 20px calc(16px + var(--safe-top));
  background-color: #0f172a;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.wizard-step-indicator {
  display: flex;
  gap: 6px;
  padding: 12px 20px;
  background-color: #f1f5f9;
}

.step-pill {
  flex: 1;
  height: 5px;
  background-color: #cbd5e1;
  border-radius: var(--radius-full);
  transition: background-color 0.2s ease;
}

.step-pill.completed {
  background-color: var(--success);
}

.step-pill.active {
  background-color: var(--primary);
}

.wizard-content {
  flex-grow: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.wizard-step-pane {
  display: none;
  flex-grow: 1;
  flex-direction: column;
  min-width: 0;
}

.wizard-step-pane.active {
  display: flex;
}

.wizard-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--text-main);
  word-break: break-word;
}

.wizard-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.wizard-footer {
  padding: 16px 20px calc(16px + var(--safe-bottom));
  background-color: #ffffff;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
}

/* Touch Numeric Keypad */
.touch-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 20px;
}

.keypad-btn {
  height: 56px;
  font-size: 22px;
  font-weight: 700;
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  min-height: 48px;
}

.keypad-btn:active {
  background-color: #e2e8f0;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS (Tablets, Mobiles, iOS & Android)
   ========================================================================== */

/* Medium Devices & Tablets (iPad, Galaxy Tab, 769px - 1024px) */
@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Small Tablets & Large Mobiles (<= 768px) */
@media (max-width: 768px) {
  /* Hide static sidebar and show mobile drawer */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    display: flex !important;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .mobile-bottom-nav {
    display: flex;
  }

  .container {
    padding: 14px 12px;
  }

  .card {
    padding: 16px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
  }

  .grid {
    gap: 12px;
  }

  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-3 { grid-template-columns: 1fr; }
  .grid-cols-2 { grid-template-columns: 1fr; }

  .topbar {
    padding: 0 12px;
    height: 56px;
  }

  .page-title {
    font-size: 16px;
    max-width: 220px;
  }

  .header-actions {
    width: 100%;
    margin-top: 6px;
  }

  .header-actions .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }

  .btn-lg {
    padding: 12px 18px;
    font-size: 15px;
    min-height: 48px;
  }

  .wizard-content {
    padding: 18px 14px;
  }

  .wizard-header {
    padding: 12px 14px calc(12px + var(--safe-top));
  }

  .wizard-footer {
    padding: 12px 14px calc(12px + var(--safe-bottom));
  }
}

/* Compact Mobiles (iPhone SE, 320px - 480px, Android Handhelds) */
@media (max-width: 480px) {
  .container {
    padding: 10px 8px;
  }

  .card {
    padding: 14px 10px;
    margin-bottom: 12px;
    border-radius: var(--radius-md);
  }

  .grid {
    gap: 10px;
  }

  .grid-cols-4 { grid-template-columns: 1fr; }
  .grid-cols-3 { grid-template-columns: 1fr; }
  .grid-cols-2 { grid-template-columns: 1fr; }

  .metric-card {
    padding: 14px 12px;
  }

  .metric-value {
    font-size: 22px;
  }

  .page-title {
    font-size: 15px;
    max-width: 160px;
  }

  .btn {
    padding: 9px 12px;
    font-size: 13px;
  }

  .btn-lg {
    padding: 11px 14px;
    font-size: 14px;
    min-height: 44px;
    width: 100%;
  }

  .header-actions .btn {
    width: 100%;
    flex: 1 1 100%;
  }

  .input-large {
    font-size: 20px !important;
    min-height: 50px !important;
    padding: 10px !important;
  }

  .topbar {
    padding: 0 10px;
  }

  .topbar-right {
    gap: 6px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
    min-width: 36px;
  }

  .data-table th, .data-table td {
    padding: 10px 12px;
    font-size: 13px;
  }

  .modal-overlay {
    padding: 8px;
  }

  .modal-overlay .card {
    padding: 16px 12px;
    max-height: 94dvh;
    border-radius: var(--radius-md);
  }

  .mobile-bottom-nav {
    padding: 4px 4px calc(4px + var(--safe-bottom));
  }

  .mobile-nav-item {
    font-size: 10px;
    padding: 2px 4px;
    gap: 2px;
  }

  .mobile-nav-item svg {
    width: 20px;
    height: 20px;
  }
}
