/* ==========================================================================
   X Forge Inventory — app.css
   Sidebar layout · Responsive · Single clean ruleset
   ========================================================================== */

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px; line-height: 1.5;
  background: #f0f2f5; color: #1a1a2e;
}
a { color: inherit; text-decoration: none; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 200px;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  display: flex; flex-direction: column; z-index: 200;
  box-shadow: 4px 0 24px rgba(0,0,0,.25);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.sidebar-brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand .brand-logo {
  font-size: 15px; font-weight: 800; color: #f8fafc;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .brand-logo .logo-icon {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-radius: 7px; display: flex; align-items: center;
  justify-content: center; font-size: 16px; flex-shrink: 0;
}
.sidebar-brand .brand-sub {
  font-size: 10px; color: rgba(255,255,255,.3);
  margin-top: 4px; padding-left: 40px;
}
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.sidebar-section-label {
  font-size: 9px; font-weight: 700; color: rgba(255,255,255,.2);
  text-transform: uppercase; letter-spacing: 1.2px; padding: 14px 18px 4px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px;
  color: rgba(255,255,255,.6); font-size: 13px; font-weight: 500;
  border-left: 3px solid transparent; margin: 1px 0; transition: all .15s;
}
.sidebar-nav a .nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-nav a:hover  { background: rgba(255,255,255,.07); color: #f8fafc; }
.sidebar-nav a.active { background: rgba(245,158,11,.15); color: #fbbf24; border-left-color: #f59e0b; font-weight: 700; }
.sidebar-footer { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.07); font-size: 11px; color: rgba(255,255,255,.25); }

/* ── Main layout ──────────────────────────────────────────────────────────── */
.main { margin-left: 200px; min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid #e2e8f0;
  padding: 0 24px; height: 54px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.topbar-title { font-size: 17px; font-weight: 700; color: #0f172a; flex: 1; min-width: 0; }
.topbar-right { font-size: 12px; color: #94a3b8; white-space: nowrap; flex-shrink: 0; }
.wrap { padding: 14px 24px; flex: 1; width: 100%; min-width: 0; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  padding: 22px 24px; margin-bottom: 20px;
  border: 1px solid #f1f5f9;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.card-title {
  font-size: 11px; font-weight: 700; color: #1e3a5f;
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 2px solid #1e3a5f; padding-bottom: 6px; margin-bottom: 10px;
}
.page-title { font-size: 20px; font-weight: 700; color: #1e3a5f; }
.page-title small { font-size: 13px; font-weight: 400; color: #888; margin-left: 8px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
label { display: block; font-size: 11px; font-weight: 700; color: #555; text-transform: uppercase; letter-spacing: .35px; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid #d0d5dd; border-radius: 7px;
  font-size: 14px; font-family: inherit; background: #fff; color: #1a1a2e;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #1e3a5f; box-shadow: 0 0 0 3px rgba(30,58,95,.12); }
input[readonly] { background: #f8f9fa; color: #555; cursor: default; }
.form-group  { display: flex; flex-direction: column; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr;       gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr;   gap: 12px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
.form-section { margin-bottom: 14px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 9px 18px; border: none; border-radius: 7px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  white-space: nowrap; font-family: inherit;
  transition: filter .15s, transform .08s;
}
.btn:hover  { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #1e3a5f; color: #fff; }
.btn-success { background: #198754; color: #fff; }
.btn-warning { background: #f0ad00; color: #1a1a2e; }
.btn-danger  { background: #dc3545; color: #fff; }
.btn-outline { background: #fff; color: #1e3a5f; border: 2px solid #1e3a5f; }
.btn-ghost   { background: #f8f9fa; color: #555; border: 1.5px solid #ddd; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 4px; border: none; font-weight: 600; cursor: pointer; }
.btn-xs.btn-warning { background: #f0ad00; color: #1a1a2e; }
.btn-xs.btn-danger  { background: #dc3545; color: #fff; }
.btn-xs.btn-success { background: #198754; color: #fff; }
.btn-xs.btn-outline { background: #fff; color: #1e3a5f; border: 1px solid #1e3a5f; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions-sticky {
  position: sticky; bottom: 0; z-index: 60;
  background: #fff; margin: 14px -24px -14px; padding: 12px 24px;
  border-top: 1px solid #e2e8f0; box-shadow: 0 -4px 12px rgba(0,0,0,.08);
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #1e3a5f; color: #fff; padding: 10px 12px; text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
tbody tr:hover { background: #f5f7fa; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { padding: 9px 12px; font-size: 13px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #888; font-size: 12px; }
.monospace { font-family: 'Consolas', 'Courier New', monospace; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-paid    { color: #155724; background: #d4edda; }
.badge-pending { color: #856404; background: #fff3cd; }
.badge-overdue { color: #721c24; background: #f8d7da; }
.badge-cancel  { color: #383d41; background: #e2e3e5; }
.badge-draft   { color: #0c5460; background: #d1ecf1; }

/* ── Custom autocomplete (replaces native <datalist>) ─────────────────────── */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 500;
  background: #fff; border: 1.5px solid #1e3a5f;
  border-top: none; border-radius: 0 0 8px 8px;
  max-height: 240px; overflow-y: auto; display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
.ac-dropdown.open { display: block; }
.ac-item {
  padding: 10px 13px; cursor: pointer; font-size: 14px;
  color: #1a1a2e; border-bottom: 1px solid #f1f5f9;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.ac-focused { background: #eff6ff; color: #1e3a5f; font-weight: 600; }
.ac-item mark { background: #fef3c7; color: inherit; border-radius: 2px; font-style: normal; }
.ac-empty { padding: 10px 13px; font-size: 13px; color: #94a3b8; font-style: italic; }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 18px; padding: 14px 16px;
  background: #f8f9fa; border-radius: 8px; border: 1px solid #eef0f3;
}
.filter-bar .form-group { min-width: 150px; }

/* Search input with icon + clear button */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap .search-icon {
  position: absolute; left: 11px; color: #94a3b8;
  font-size: 14px; pointer-events: none; z-index: 1;
}
.search-wrap input[name="q"] { padding-left: 34px !important; padding-right: 30px !important; }
.search-clear {
  position: absolute; right: 7px;
  background: none; border: none; cursor: pointer;
  color: #94a3b8; font-size: 15px; line-height: 1;
  padding: 3px 5px; border-radius: 4px;
  display: none; align-items: center; justify-content: center;
  z-index: 1;
}
.search-clear:hover { color: #1e3a5f; background: #e8eef4; }

/* Shortcut hint in label */
.search-hint { font-size: 10px; color: #bbb; font-weight: 400; margin-left: 4px; }

/* Result count */
.search-count { font-size: 12px; color: #94a3b8; margin-bottom: 12px; }

/* ── Totals box ───────────────────────────────────────────────────────────── */
.totals-box { margin-left: auto; min-width: 280px; border: 1px solid #eef0f3; border-radius: 6px; overflow: hidden; }
.totals-box table { font-size: 14px; }
.totals-box thead th { padding: 0; height: 0; font-size: 0; border: none; background: none; }
.totals-box td { padding: 8px 14px; border-bottom: 1px solid #eef0f3; }
.totals-box tr:last-child td { border-bottom: none; }
.totals-box .grand-row { background: #1e3a5f; color: #fff; font-size: 15px; font-weight: 700; }
.totals-box .grand-row td { border-bottom: none; }

/* ── Paid panel ───────────────────────────────────────────────────────────── */
.paid-panel { display: none; padding: 14px 16px; background: #f0fff4; border: 1px solid #b7dfc5; border-radius: 6px; margin-top: 10px; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert { padding: 12px 18px; border-radius: 7px; margin-bottom: 18px; font-weight: 600; border: 1.5px solid transparent; }
.alert-success { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.alert-error   { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border-color: #ffeeba; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; margin-top: 16px; justify-content: center; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 12px; border: 1.5px solid #d0d5dd; border-radius: 6px;
  font-size: 13px; background: #fff; color: #1e3a5f; transition: background .1s;
}
.pagination a:hover    { background: #f0f4f8; }
.pagination .pg-active { background: #1e3a5f; color: #fff; border-color: #1e3a5f; }
.pagination .pg-dots   { border: none; background: none; color: #888; }
.pagination .pg-arrow  { font-weight: 700; min-width: 80px; text-align: center; }
.pagination .pg-disabled { color: #ccc; cursor: default; pointer-events: none; border-color: #eee; background: #fafafa; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: #888; }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── Steel picker ─────────────────────────────────────────────────────────── */
#steel-picker { background: #eff6ff; border: 1.5px solid #bfdbfe; border-radius: 8px; }

/* ── Inventory item link & badges ─────────────────────────────────────────── */
.item-link { color: inherit; font-weight: 600; }
.item-link:hover { color: #1e3a5f; text-decoration: underline; }
.badge-out { color: #dc3545; font-weight: 700; font-size: 11px; margin-right: 4px; }
.badge-low { color: #f0ad00; font-weight: 700; font-size: 11px; margin-right: 4px; }
.inv-act { white-space: nowrap; text-align: center; }

/* ── Hamburger (desktop: hidden) ──────────────────────────────────────────── */
.hamburger {
  display: none; flex-direction: column; justify-content: center;
  gap: 5px; width: 44px; height: 44px; padding: 10px;
  background: none; border: none; cursor: pointer; border-radius: 7px;
  flex-shrink: 0; margin-right: 8px;
}
.hamburger:hover { background: #f1f5f9; }
.hamburger span { display: block; height: 2px; background: #1e3a5f; border-radius: 2px; }

/* ── Sidebar backdrop ─────────────────────────────────────────────────────── */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }
.sidebar-backdrop.open { display: block; }

/* ── Copy-to-clipboard preview modal ──────────────────────────────────────── */
.copy-modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 999; align-items: center; justify-content: center; padding: 20px;
}
.copy-modal {
  background: #fff; border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,.25);
  padding: 20px; width: 100%; max-width: 480px;
}
.copy-modal-title { font-weight: 700; font-size: 14px; margin-bottom: 12px; color: #1e3a5f; }
.copy-modal textarea {
  width: 100%; min-height: 240px; font-family: 'Courier New', monospace; font-size: 13px;
  line-height: 1.5; padding: 10px; border: 1.5px solid #d0d5dd; border-radius: 7px;
  resize: vertical; white-space: pre-wrap;
}
.copy-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ── "Are you sure?" confirm modal (replaces native window.confirm) ────────── */
.confirm-modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 1000; align-items: center; justify-content: center; padding: 20px;
}
.confirm-modal {
  background: #fff; border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,.25);
  padding: 22px; width: 100%; max-width: 380px;
}
.confirm-modal-msg { font-size: 14px; color: #1e293b; line-height: 1.5; white-space: pre-line; }
.confirm-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ── Copy-format choice (radio buttons in the confirm-modal shell) ─────────── */
.copy-format-option {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1.5px solid #e2e8f0; border-radius: 8px; margin-bottom: 8px; cursor: pointer;
}
.copy-format-option:hover { border-color: #93c5fd; background: #f8fafc; }
.copy-format-option input { margin-top: 3px; }
.copy-format-option small { color: #64748b; }


/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .no-print, .filter-bar, .actions, .pagination { display: none !important; }
  .main { margin-left: 0; }
  .wrap { padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; }
  body  { background: #fff; }
}

/* ── Tablet (769–1024px) ──────────────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 170px; }
  .main    { margin-left: 170px; }
  .form-grid-3, .form-grid-4 { grid-template-columns: 1fr 1fr !important; }
  .wrap { padding: 16px 18px; }
}

/* ── Mobile (≤768px) ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Sidebar off-canvas */
  .sidebar { transform: translateX(-100%); width: 260px !important; z-index: 300; }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: flex; }

  /* Main: full width, clips own overflow so page doesn't scroll sideways */
  .main { margin-left: 0 !important; width: 100vw; overflow-x: hidden; }

  /* Wrap: fills container, resets margins that cause flex-shrink issues */
  .wrap { padding: 10px 12px !important; margin: 0 !important; width: 100% !important; max-width: 100% !important; }

  /* Topbar */
  .topbar { padding: 0 10px; height: 52px; }
  .topbar-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; margin-right: 8px; }
  .topbar-right { font-size: 11px; }

  /* Cards */
  .card { padding: 12px; margin-bottom: 10px; border-radius: 8px; }

  /* Grids → single column. Covers both class-based and inline style grids */
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr !important; gap: 8px !important; }
  [style*="grid-template-columns"]           { grid-template-columns: 1fr !important; }

  /* Inputs: 16px stops iOS from zooming in on focus */
  input, select, textarea { font-size: 16px !important; }

  /* Filter bar */
  .filter-bar { flex-direction: column; gap: 8px; padding: 10px; }
  .filter-bar .form-group { min-width: 0 !important; width: 100%; }

  /* Buttons: tap-friendly */
  .btn    { min-height: 44px; padding: 10px 16px; font-size: 14px; }
  .btn-sm { min-height: 38px; padding: 8px 12px;  font-size: 13px; }
  .btn-xs { min-height: 34px; padding: 6px 10px;  font-size: 12px; border-radius: 5px; }
  .actions > .btn { flex: 1 1 auto; min-width: 100px; justify-content: center; }

  /* Tables: scroll inside their container, never squeeze columns */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #eef0f3;
    border-radius: 6px;
  }
  table      { width: auto; min-width: 100%; font-size: 12px; }
  thead th   { padding: 8px 10px; font-size: 10px; white-space: nowrap; }
  tbody td   { padding: 8px 10px; white-space: nowrap; }
  tfoot td   { padding: 8px 10px; }

  /* Small scroll hint under tables */
  .table-wrap::after {
    content: '↔ swipe to see more';
    display: block;
    text-align: center;
    font-size: 10px;
    color: #bbb;
    padding: 3px 0;
  }

  /* Totals box */
  .totals-box { min-width: 0; width: 100%; margin-left: 0; }

  /* Inline flex tab bars (invoices, statements) → scrollable row */
  [style*="display:flex"][style*="gap:0"],
  [style*="display: flex"][style*="gap: 0"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }
  [style*="display:flex"][style*="gap:0"]::-webkit-scrollbar  { display: none; }

  /* Class-based tab bars */
  .st-tabs, .tq-tabs {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important; scrollbar-width: none; padding-bottom: 2px;
  }
  .st-tabs::-webkit-scrollbar, .tq-tabs::-webkit-scrollbar { display: none; }
  .st-tab, .tq-tab { white-space: nowrap; font-size: 12px; padding: 8px 14px; flex-shrink: 0; }

  /* Invoice tab buttons */
  .inv-tab { font-size: 13px !important; padding: 10px 16px !important; white-space: nowrap; }

  /* Pagination */
  .pagination a, .pagination span { padding: 8px 14px; min-height: 44px; display: flex; align-items: center; }

  /* ── Inventory table → card layout ────────────────────────────────────── */
  /* Hide normal table chrome */
  #inv-table thead               { display: none; }
  #inv-table,
  #inv-table tbody               { display: block; }
  #inv-table tr                  { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px;
                                   background: #fff; border: 1px solid #e8edf3; border-radius: 10px;
                                   padding: 12px; margin-bottom: 10px;
                                   box-shadow: 0 1px 3px rgba(0,0,0,.06); }
  #inv-table td                  { display: block; border: none; padding: 2px 0;
                                   font-size: 13px; white-space: normal; }

  /* Description: full-width first row */
  #inv-table td:first-child      { grid-column: 1 / -1; font-size: 15px; font-weight: 700;
                                   color: #1a1a2e; padding-bottom: 8px;
                                   border-bottom: 1px solid #f1f5f9; margin-bottom: 4px; }

  /* Data cells with labels */
  #inv-table td[data-label]::before {
    content: attr(data-label) ': ';
    font-size: 10px; font-weight: 700; color: #94a3b8;
    text-transform: uppercase; letter-spacing: .4px;
  }

  /* Action cell: full-width, flex row of buttons */
  #inv-table td.inv-act          { grid-column: 1 / -1; display: flex !important; gap: 6px;
                                   flex-wrap: wrap; padding-top: 10px;
                                   border-top: 1px solid #f1f5f9; margin-top: 4px; }
  #inv-table td.inv-act .btn-xs  { flex: 1; min-height: 42px; min-width: 48px;
                                   display: inline-flex; align-items: center; justify-content: center;
                                   border-radius: 7px; font-size: 13px; font-weight: 700; }
  /* Make sure no-print doesn't hide actions on mobile */
  @media (max-width: 768px) { #inv-table td.inv-act { display: flex !important; } }

  /* ── Line-items table (invoices/quotes/POs) → card layout ─────────────── */
  #items-tbl thead              { display: none; }
  #items-tbl,
  #items-tbl tbody              { display: block; }
  #items-tbl tr                 { display: block; background: #fff; border: 1px solid #e8edf3;
                                   border-radius: 10px; padding: 12px; margin-bottom: 10px;
                                   box-shadow: 0 1px 3px rgba(0,0,0,.06); }
  #items-tbl td                 { display: block; border: none; padding: 6px 0; white-space: normal; }
  #items-tbl td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: 10px; font-weight: 700; color: #94a3b8;
    text-transform: uppercase; letter-spacing: .4px; margin-bottom: 3px;
  }
  #items-tbl td.line-total      { font-size: 15px; font-weight: 700; color: #1e3a5f;
                                   border-top: 1px solid #f1f5f9; padding-top: 10px; margin-top: 4px; }
  #items-tbl td:last-child      { display: flex !important; justify-content: flex-end;
                                   padding-top: 10px; margin-top: 6px; border-top: 1px solid #f1f5f9; }
  #items-tbl td:last-child .btn-xs { min-height: 38px; min-width: 38px; padding: 0 14px;
                                   border-radius: 7px; font-size: 13px; font-weight: 700; }
}
