/* ============================================================
   MUDFOX LTD — Admin Styles — Mobile-first Responsive
   ============================================================ */

:root {
  --mf-green:   #1D9E75;
  --mf-dark:    #0F3D2E;
  --mf-light:   #E1F5EE;
  --mf-accent:  #1D9E75;
  --sidebar-w:  220px;
  --topbar-h:   56px;
}

/* ── Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }

/* ── Topbar ──────────────────────────────────────────────── */
.mudfox-topbar {
  background: var(--mf-dark);
  height: var(--topbar-h);
  position: sticky;
  top: 0;
  z-index: 1040;
  width: 100%;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.12); }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.topbar-brand img { height: 30px; border-radius: 4px; flex-shrink: 0; }
.topbar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-user { color: rgba(255,255,255,.65); font-size: 13px; white-space: nowrap; }

/* ── Sidebar overlay ─────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1049;
}
.sidebar-overlay.open { display: block; }

/* ── Sidebar ─────────────────────────────────────────────── */
.mudfox-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #f8f9fa;
  border-right: 1px solid #dee2e6;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  transition: transform .25s ease;
  padding: 8px;
}

.mudfox-sidebar .nav-link {
  color: #495057;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mudfox-sidebar .nav-link:hover { background: var(--mf-light); color: var(--mf-dark); }
.mudfox-sidebar .nav-link.active { background: var(--mf-green); color: #fff; }
.mudfox-sidebar .nav-link i { width: 16px; text-align: center; flex-shrink: 0; }

.sidebar-divider {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #adb5bd;
  padding: 14px 12px 4px;
}

/* ── Layout wrapper ──────────────────────────────────────── */
.mudfox-wrapper {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
  width: 100%;
  overflow-x: hidden;
}

.mudfox-main {
  background: #f4f6f8;
  flex: 1;
  min-width: 0;       /* critical — prevents flex child overflow */
  width: 0;           /* forces flex to respect parent width */
  padding: 24px;
  overflow-x: hidden;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 20px; font-weight: 700; margin: 0; }
.page-header .page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Cards ───────────────────────────────────────────────── */
.card { border: 1px solid #e0e4e8; border-radius: 10px; }
.card-header { font-weight: 600; background: #fff; border-bottom: 1px solid #e0e4e8; }
.kpi-card { border-left: 4px solid var(--mf-green); }
.kpi-card .kpi-value { font-size: 26px; font-weight: 700; color: var(--mf-dark); }
.kpi-card .kpi-label { font-size: 11px; color: #6c757d; text-transform: uppercase; letter-spacing: .05em; }

/* ── Tables ──────────────────────────────────────────────── */
.table th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #6c757d; white-space: nowrap; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: #f0f7f4; }
.table-responsive { -webkit-overflow-scrolling: touch; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn-mf { background: var(--mf-green); color: #fff; border: none; }
.btn-mf:hover { background: var(--mf-dark); color: #fff; }

/* ── Forms ───────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: 14px; }
.required-star::after { content: ' *'; color: #dc3545; }

/* ── Invoice/quote builder ───────────────────────────────── */
.line-items-table th { background: var(--mf-light); }
.line-items-table .btn-remove-item { color: #dc3545; }
.totals-box { background: #f8f9fa; border-radius: 8px; padding: 16px; }
.totals-box .total-row { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-box .grand-total { font-weight: 700; font-size: 18px; border-top: 2px solid #dee2e6; padding-top: 8px; margin-top: 4px; }

/* ── Auth ────────────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--mf-dark) 0%, #1a5c45 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card { background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo img { height: 48px; }
.auth-logo h2 { font-size: 20px; font-weight: 700; margin-top: 8px; color: var(--mf-dark); }

/* ── Portal ──────────────────────────────────────────────── */
.portal-topbar { background: var(--mf-dark); }
.portal-main { min-height: calc(100vh - 56px); background: #f4f6f8; padding: 32px; }

/* ── Timeline ────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: #dee2e6; }
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-item::before { content: ''; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--mf-green); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--mf-green); }

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .mudfox-sidebar, .mudfox-topbar, .sidebar-overlay, .sidebar-toggle, .no-print { display: none !important; }
  .mudfox-main { padding: 0 !important; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤992px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 992px) {
  .mudfox-main { padding: 16px; }
  .kpi-card .kpi-value { font-size: 22px; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤768px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Show hamburger */
  .sidebar-toggle { display: block; }
  .topbar-user { display: none !important; }

  /* Sidebar becomes fixed drawer */
  .mudfox-sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 1050;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
    padding-top: 64px;
  }
  .mudfox-sidebar.open { transform: translateX(0); }

  /* Full width main */
  .mudfox-wrapper { display: block; }
  .mudfox-main { width: 100%; padding: 10px; }

  /* Page header — stack vertically */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
  }
  .page-header h1 { font-size: 17px; }

  /* Action buttons in page header — wrap nicely */
  .page-header .d-flex.gap-2,
  .page-header .d-flex.flex-wrap,
  .page-header > .d-flex {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px !important;
  }
  .page-header > .d-flex > a,
  .page-header > .d-flex > button,
  .page-header > .d-flex > form { width: 100%; }
  .page-header > .d-flex > form > button { width: 100%; }

  /* Single action button — full width */
  .page-header > a.btn,
  .page-header > button.btn { width: 100%; }

  /* Status tabs — horizontal scroll */
  .d-flex.gap-1.mb-3 {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 4px !important;
  }
  .d-flex.gap-1.mb-3 .btn { flex-shrink: 0; font-size: 12px; padding: 5px 10px; }

  /* Filter bar — stack vertically */
  .card-body .d-flex.flex-wrap.gap-2 {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .card-body .d-flex.flex-wrap.gap-2 input[type="text"],
  .card-body .d-flex.flex-wrap.gap-2 input[type="date"],
  .card-body .d-flex.flex-wrap.gap-2 select { width: 100% !important; max-width: 100% !important; }
  .card-body .d-flex.flex-wrap.gap-2 .btn { width: 100%; }
  .card-body .d-flex.flex-wrap.gap-2 .ms-auto { margin-left: 0 !important; }

  /* Row columns — full width on mobile */
  .row > [class*="col-md-"],
  .row > [class*="col-lg-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* Exception: 2-column KPI grid */
  .row.g-3 > .col-6,
  .row.g-4 > .col-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  /* Table cells */
  .table th, .table td { font-size: 12px; padding: 8px 6px; }
  .hide-mobile { display: none !important; }

  /* Cards */
  .card { border-radius: 8px; margin-bottom: 12px; }

  /* Auth card */
  .auth-card { padding: 24px 18px; }

  /* Portal */
  .portal-main { padding: 10px; }

  /* Invoice/quote show — right column goes below main content */
  /* Already handled by col-md force above */

  /* Action button groups inside page-header — icon + text */
  .page-header .btn .bi + span,
  .page-header .btn .bi ~ *:not(.badge) { font-size: 12px; }

  /* Modals — near full screen */
  .modal-dialog { margin: 8px; }
  .modal-dialog:not(.modal-fullscreen) { max-width: calc(100vw - 16px); }

  /* Tables in show pages — make them scroll */
  .table-responsive { overflow-x: auto; }

  /* Breadcrumb — smaller */
  .breadcrumb { font-size: 12px; }

  /* dl rows in customer detail */
  .row.mb-0.small .col-sm-4 { flex: 0 0 40%; max-width: 40%; }
  .row.mb-0.small .col-sm-8 { flex: 0 0 60%; max-width: 60%; }

  /* Totals box */
  .totals-box .grand-total { font-size: 16px; }

  /* Badge pills in tabs */
  .badge { font-size: 10px; }

  /* Invoice show actions — wrap into 2 col grid */
  .page-header .d-flex.flex-wrap.gap-2 {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px !important;
  }
  .page-header .d-flex.flex-wrap.gap-2 > * { min-width: 0; }

  /* Nav tabs — scroll horizontally */
  .nav-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; border-bottom: 0; }
  .nav-tabs .nav-item { flex-shrink: 0; }
  .nav-tabs .nav-link { white-space: nowrap; font-size: 13px; padding: 8px 14px; }
  .tab-content { border-top: 1px solid #dee2e6; padding-top: 12px; }

  /* Settings tabs sidebar — stack on mobile */
  .nav-pills.flex-column { flex-direction: row !important; flex-wrap: nowrap; overflow-x: auto; margin-bottom: 12px; }
  .nav-pills.flex-column .nav-link { white-space: nowrap; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Small mobile (≤480px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .mudfox-main { padding: 8px; }
  .page-header h1 { font-size: 15px; }

  /* KPI — single column on tiny phones */
  .row.g-3 > .col-6 { flex: 0 0 100%; max-width: 100%; }

  .kpi-card .kpi-value { font-size: 20px; }

  /* Topbar brand text shorter */
  .topbar-brand span { font-size: 14px; }

  /* Action grid single column */
  .page-header > .d-flex {
    grid-template-columns: 1fr !important;
  }
}
