/* =========================================================
   THEME VARIABLES
   ========================================================= */
:root {
  --md-primary: #c62828;
  --md-primary-dark: #9a0007;
  --md-bg: #f5f6f8;
  --md-surface: #ffffff;
  --md-text: #1c1b1f;
  --md-muted: #6f6f6f;
  --md-radius: 12px;
  --md-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  margin: 0;
}

/* =========================================================
   BASE / RESET
   ========================================================= */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--md-bg);
  color: var(--md-text);
  overflow-x: hidden;
  min-height: 100vh;
  height: auto;
}

body {
  overflow-y: auto;
}

/* =========================================================
   LAYOUT
   ========================================================= */
/* Fixed navbar spacing */
body {
  padding-top: 70px;
}

.container { padding: 24px; }

.card {
  background: var(--md-surface);
  border-radius: var(--md-radius);
  box-shadow: var(--md-shadow);
  padding: 20px;
  margin-bottom: 20px;
}

/* =========================================================
   HEADER
   ========================================================= */
.app-header {
  background: var(--md-surface);
  box-shadow: var(--md-shadow);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
}

.brand img { height: 72px; }

/* =========================================================
   BUTTONS - Bootstrap handles most button styles
   ========================================================= */

/* Keep custom button for actions trigger if needed */
.actions-trigger {
  /* Specific styling handled in admin.css if needed */
}


/* =========================================================
   FORMS
   ========================================================= */
input, select, textarea {
  width: 100%;
  padding: 10px;
  border-radius: var(--md-radius);
  border: 1px solid #ccc;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--md-primary);
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* =========================================================
   TABLES (DESKTOP ONLY)
   ========================================================= */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

th {
  text-align: left;
  font-weight: 600;
  color: var(--md-muted);
  padding: 12px;
  border-bottom: 1px solid #ddd;
}

td {
  padding: 12px;
  border-bottom: 1px solid #eee;
}

tr:hover { background: #f9f9f9; }

/* =========================================================
   DROPDOWNS / MENUS
   ========================================================= */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  min-width: 200px;
  background: #fff;
  border: 1px solid #ddd;
  display: none;
  z-index: 20;
}

/* Portal dropdowns - ensure they don't affect body scrolling */
.dropdown-menu.portal {
  position: fixed;
  display: block;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-radius: 6px;
  pointer-events: auto;
}

.dropdown-menu button {
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  text-align: left;
}
.dropdown-menu button:hover { background: #f5f5f5; }

.dropdown-menu.show { display: block; }

/* =========================================================
   DASHBOARD FILTERS
   ========================================================= */
.dashboard-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.filter-row {
  display: flex;
  flex-direction: column;
}

.filter-actions {
  padding-top: 10px;
  grid-column: 1 / -1;
  text-align: right;
}

/* =========================
   Dashboard fixed totals bar
   ========================= */

.totals-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  z-index: 100;

  display: flex;
  justify-content: space-between;
  gap: 16px;

  padding: 12px 20px;

  background: #ffffff;
  border-top: 2px solid #e0e0e0;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.15);

  font-size: 15px;
}

.totals-bar span {
  font-weight: 700;
}

/* Mobile layout */
@media (max-width: 768px) {
  .totals-bar {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    padding: 10px 16px;
  }
}




/* =========================================================
   PO STATUS / FINANCIAL STATES
   ========================================================= */
.po-complete    { background: #d1e7dd; }
.po-outstanding { background: #fff3cd; }
.po-over        { background: #f8d7da; }

.ok   { color: #198754; font-weight: 600; }
.warn { color: #d39e00; font-weight: 600; }
.over { color: #dc3545; font-weight: 700; }

/* =========================================================
   DETAILS / INVOICES
   ========================================================= */
.details-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.details-row td { background: #fafafa; }

.sub-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
}

.sub-table th,
.sub-table td {
  padding: 6px 8px;
  font-size: 13px;
  border-bottom: 1px solid #e0e0e0;
}

.invoice-container { margin-top: 12px; }

.muted { color: #777; font-size: 13px; }

/* =====================================================
   HEADER – DESKTOP LAYOUT LOCK
   ===================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  flex-direction: row;      /* 🔒 force side-by-side */
  align-items: center;
  gap: 12px;
  width: auto;
}

.header-actions button {
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}





/* =========================================================
   MOBILE (CLEAN + SCOPED)
   ========================================================= */
@media (max-width: 768px) {

  body { font-size: 14px; }
  .container { padding: 12px; }

  /* Header */
  .app-header {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
  }

  .brand {
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .brand img { height: 48px; }

  .brand h1 {
    font-size: 25px;
    text-align: center;
  }

  .header-actions {
    width: 100%;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .header-actions button {
    flex: 1;
    min-height: 42px;
  }

@media (max-width: 768px) {

  /* Invoice scroll – simple, non-invasive */
  .invoice-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .invoice-container .sub-table {
    min-width: 600px;
  }
}



  /* ===============================
     MAIN PO LIST → CARDS ONLY
     =============================== */
  .po-table thead {
    display: none;
  }

  .po-table > tbody > tr:not(.details-row) {
    display: block;
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: var(--md-shadow);
  }

  .po-table > tbody > tr:not(.details-row) td {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border: none;
  }

  .po-table > tbody > tr:not(.details-row) td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--md-muted);
  }

  /* ===============================
     EXPANDED PO DETAILS (FULL WIDTH)
     =============================== */
  .details-row {
    display: block;
  }

  .details-row td {
    display: block;
    padding: 14px;
  }

  .details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .details-grid > div {
    display: flex;
    justify-content: space-between;
  }

  /* ===============================
     INVOICES (SCROLL ONLY HERE)
     =============================== */
  .invoice-container {
    overflow-x: auto;
    margin-top: 12px;
  }

  .sub-table {
    min-width: 600px;
  }

  /* ===============================
     ACTION BUTTONS
     =============================== */
  .details-actions {
    flex-direction: column;
    gap: 10px;
  }

  .details-actions button {
    width: 100%;
  }
}

/* =========================================================
   BACKDROP
   ========================================================= */
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
}



/* =====================================================
   DASHBOARD – PREVENT TABLE-IN-TABLE WIDTH EXPANSION
   ===================================================== */


/* Ensure container never expands parent table */
.invoice-container {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Safety: prevent parent table expansion */
.po-table {
  width: 100%;
  table-layout: fixed;
}

/* =====================================================
   DASHBOARD – DO NOT STACK INVOICE TABLES ON MOBILE
   ===================================================== */
@media (max-width: 768px) {

  /* Restore normal table layout for invoice tables */
  .invoice-container .data-table,
  .invoice-container .data-table thead,
  .invoice-container .data-table tbody,
  .invoice-container .data-table tr {
    display: table;
    width: 100%;
  }

  .invoice-container .data-table th,
  .invoice-container .data-table td {
    display: table-cell;
    white-space: nowrap;
  }

  /* Keep header visible */
  .invoice-container .data-table thead {
    display: table-header-group;
  }
}


/* =====================================================
   DASHBOARD – MINIMAL INVOICE VIEW ON MOBILE
   ===================================================== */
@media (max-width: 768px) {

  /* Dashboard invoice tables only */
  .invoice-container .data-table th,
  .invoice-container .data-table td {
    display: none;
  }

  /* Show Date (2nd column) */
  .invoice-container .data-table th:nth-child(2),
  .invoice-container .data-table td:nth-child(2) {
    display: table-cell;
  }

  /* Show Total (inc VAT) (5th column) */
  .invoice-container .data-table th:nth-child(5),
  .invoice-container .data-table td:nth-child(5) {
    display: table-cell;
  }

  /* Align nicely */
  .invoice-container .data-table td:nth-child(5),
  .invoice-container .data-table th:nth-child(5) {
    text-align: right;
    font-weight: 600;
  }
}

/* =====================================================
   INVOICE ENTRY – MINIMAL TABLE ON MOBILE
   ===================================================== */
@media (max-width: 768px) {

  /* Hide all columns by default */
  .data-table th,
  .data-table td {
    display: none;
  }

  /* Show Date (2nd column) */
  .data-table th:nth-child(2),
  .data-table td:nth-child(2) {
    display: table-cell;
  }

  /* Show Total (inc VAT) (5th column) */
  .data-table th:nth-child(5),
  .data-table td:nth-child(5) {
    display: table-cell;
    text-align: right;
    font-weight: 600;
  }

  /* Show Actions (6th column) */
  .data-table th:nth-child(6),
  .data-table td:nth-child(6) {
    display: table-cell;
    text-align: right;
  }
}


/* =========================
   PO expand / collapse
   ========================= */

.details-wrapper {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition:
    max-height 1s ease,
    opacity 1s ease;
}

/* Expanded state */
.details-row.open .details-wrapper {
  max-height: 2000px; /* large enough for invoices */
  opacity: 1;
}

/* =========================
   Active PO highlight
   ========================= */

.po-row {
  cursor: pointer;
}

.po-row.active {
  border-left: #0100ff 5px solid;
}

.po-row.active td {
  font-weight: 600;
}

/* Mobile: keep it subtle */
@media (max-width: 768px) {
  .po-row.active {
    border-left: #0100ff 5px solid;
  }
}

/* =========================
   Create PO – mobile form fix
   ========================= */
@media (max-width: 768px) {

  #poForm {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  #poForm select,
  #poForm input,
  #poForm textarea {
    font-size: 16px;              /* ⬅️ critical for mobile */
    padding: 12px 14px;
    border-radius: 12px;
  }

  #poForm textarea {
    min-height: 100px;
  }

  #poForm p {
    font-size: 15px;
    margin: 4px 0;
  }

  #poForm button.btn-primary {
    font-size: 16px;
    padding: 14px;
    border-radius: 999px;
  }

  /* Give the card breathing room */
  .container > .card {
    padding: 16px;
  }
}

/* Space for fixed totals bar */
.container {
  padding-bottom: 90px;
}

/* Slightly taller on mobile */
@media (max-width: 768px) {
  .container {
    padding-bottom: 120px;
  }
}

/* =====================================================
   SUPPLIERS – ALWAYS TABLE (NO CARD MODE)
   ===================================================== */
@media (max-width: 768px) {
  .suppliers-table {
    width: 100%;
    border-collapse: collapse;
  }

  .suppliers-table thead {
    display: table-header-group;
  }

  .suppliers-table tr {
    display: table-row;
  }

  .suppliers-table th,
  .suppliers-table td {
    display: table-cell;
    padding: 12px;
    border-bottom: 1px solid #eee;
  }
}


/* ===== ACTIONS DROPDOWN ===== */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;

  background: #fff;
  border-radius: 12px;
  padding: 6px 0;

  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  border: 1px solid rgba(0,0,0,0.06);

  z-index: 1000;
}

/* Individual menu items */
.dropdown-menu a,
.dropdown-menu button,
.dropdown-menu div {
  display: block;
  padding: 10px 16px;

  font-size: 14px;
  font-weight: 500;
  color: #222;
  text-decoration: none;
  white-space: nowrap;

  cursor: pointer;
}

/* Hover state */
.dropdown-menu a:hover,
.dropdown-menu button:hover,
.dropdown-menu div:hover {
  background: #f7f7f7;
  color: #c62828;
}

/* Optional divider */
.dropdown-menu .divider {
  height: 1px;
  margin: 6px 0;
  background: #eee;
}

.hidden {
  display: none !important;
}
