/* =========================================================
   Food Formula Management System â€” Clean Professional ERP
   Light theme Â· no black backgrounds
   ========================================================= */

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  --primary: #1f6f8b;
  --primary-hover: #185a71;
  --primary-light: #e6f2f6;
  --primary-border: #9fc5d4;

  --success: #1f7a4c;
  --success-bg: #e6f6ee;
  --warning: #9a6700;
  --warning-bg: #fff6db;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --info: #1a6fa8;
  --info-bg: #e8f3fb;

  --text: #243447;
  --text-muted: #6b7c8c;
  --border: #d5dee7;
  --border-soft: #e8eef3;

  --bg: #f0f3f6;
  --surface: #ffffff;
  --sidebar: #ffffff;
  --header: #ffffff;

  --table-head-bg: #e8f1f5;
  --table-head-text: #1f4f63;
  --table-foot-bg: #dce9ef;

  --sidebar-w: 248px;
  --header-h: 56px;
  --radius: 6px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --shadow: 0 1px 2px rgba(36, 52, 71, 0.06);
  --shadow-md: 0 4px 14px rgba(36, 52, 71, 0.08);
  --transition: 0.15s ease;
}

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

html {
  font-size: 14px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--text);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: transform var(--transition);
}

.sidebar-brand {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--header-h);
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.sidebar-brand .brand-text h1 {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}

.sidebar-brand .brand-text span {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 0.85rem 0.7rem;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.65rem 0.75rem 0.35rem;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  margin-bottom: 0.2rem;
  transition: background var(--transition), color var(--transition);
  font-size: 0.88rem;
  font-weight: 500;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item .nav-icon {
  width: 22px;
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.85;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 0.9rem 1.1rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sidebar-footer strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(30, 90, 140, 0.18), transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(46, 125, 79, 0.12), transparent 45%),
    linear-gradient(160deg, #e8eef4 0%, #f4f7fa 45%, #eef2f0 100%);
}

.login-screen[hidden],
.app-layout[hidden] {
  display: none !important;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem 1.75rem 1.5rem;
  box-shadow: 0 12px 40px rgba(20, 40, 70, 0.08);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-brand .brand-icon {
  margin: 0 auto 0.75rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}

.login-brand p {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-card .form-group {
  margin-bottom: 1rem;
}

.login-card label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.login-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 90, 140, 0.12);
}

.login-error {
  color: #b42318;
  font-size: 0.82rem;
  margin: 0 0 0.75rem;
}

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

.login-hint {
  margin: 1rem 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 0.35rem;
}

.user-chip-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.header {
  height: var(--header-h);
  background: var(--header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.35rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.menu-toggle {
  display: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--text);
  padding: 0.3rem 0.5rem;
}

.page-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.page-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.page-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.content-area {
  flex: 1;
  padding: 1.25rem 1.35rem 1.75rem;
}

.view-intro {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-soft);
}

.view-intro h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.view-intro p {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 70ch;
}

/* ---------- Views ---------- */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  overflow: hidden;
}

.card-header {
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.card-header h2,
.card-header h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  padding: 1.1rem;
}

.card-footer {
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  background: #fafbfc;
}

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  transition: box-shadow var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card.beverage { border-left-color: #1a6fa8; }
.stat-card.namkeen { border-left-color: #c47a1a; }
.stat-card.pickle { border-left-color: #1f7a4c; }
.stat-card.makhan { border-left-color: #b04a7a; }
.stat-card.draft { border-left-color: #6b7c8c; }
.stat-card.approved { border-left-color: #1f7a4c; }
.stat-card.completed { border-left-color: #1f6f8b; }

.stat-card .stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.stat-card .stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-card .stat-hint {
  margin-top: 0.35rem;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.dashboard-panels {
  display: grid;
  grid-template-columns: 1.45fr 0.85fr;
  gap: 1rem;
}

@media (max-width: 980px) {
  .dashboard-panels {
    grid-template-columns: 1fr;
  }
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  text-align: left;
  width: 100%;
  color: inherit;
}

.quick-action:hover {
  border-color: var(--primary-border);
  background: var(--primary-light);
}

.quick-action .qa-icon {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.quick-action .qa-text strong {
  display: block;
  font-size: 0.86rem;
  color: var(--text);
  font-weight: 600;
}

.quick-action .qa-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.48rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 0.84rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
  border-color: #c0ccd6;
}

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

.btn-success:hover:not(:disabled) {
  background: #18633e;
}

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

.btn-danger:hover:not(:disabled) {
  background: #a33226;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}

.btn-warning:hover:not(:disabled) {
  background: #7a5200;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.76rem;
}

.btn-icon {
  padding: 0.3rem 0.45rem;
  min-width: 28px;
}

.btn-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.8rem;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toolbar .spacer {
  flex: 1;
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.95rem;
}

.form-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text);
}

.form-group label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-control {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 139, 0.12);
}

.form-control:read-only,
.form-control:disabled {
  background: #f5f7f9;
  color: var(--text-muted);
  cursor: default;
}

.form-control.error {
  border-color: var(--danger);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.form-error {
  font-size: 0.7rem;
  color: var(--danger);
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

table.data-table th,
table.data-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

table.data-table th {
  background: var(--table-head-bg);
  font-weight: 600;
  color: var(--table-head-text);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

table.erp-grid thead th {
  background: var(--table-head-bg);
  color: var(--table-head-text);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border-soft);
  padding: 0.7rem 0.8rem;
}

table.erp-grid thead th:last-child {
  border-right: none;
}

table.erp-grid tbody td {
  border-right: 1px solid var(--border-soft);
}

table.erp-grid tbody td:last-child {
  border-right: none;
}

table.erp-grid tbody tr:nth-child(even) {
  background: #f8fafb;
}

table.erp-grid tbody tr:hover {
  background: var(--primary-light);
}

table.erp-grid tfoot td {
  background: var(--table-foot-bg);
  color: var(--table-head-text);
  font-weight: 700;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border-soft);
  padding: 0.7rem 0.8rem;
}

table.erp-grid tfoot td:last-child {
  border-right: none;
}

table.erp-grid tfoot td.num-unit {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.ingredient-table td.num-unit {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text);
  background: #f3f7f9;
}

table.ingredient-table select.material-unit-select {
  min-width: 78px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-hover);
  text-align: center;
  cursor: pointer;
}

table.ingredient-table select.material-unit-select:focus {
  box-shadow: 0 0 0 3px rgba(31, 111, 139, 0.15);
  border-color: var(--primary);
}

table.ingredient-table select.material-unit-select option {
  background: #fff;
  color: var(--text);
}

table.data-table:not(.erp-grid) tbody tr:hover {
  background: var(--primary-light);
}

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

table.erp-grid tbody tr:last-child td {
  border-bottom: 1px solid var(--border-soft);
}

table.data-table .actions-cell {
  white-space: nowrap;
}

table.data-table input.form-control,
table.data-table select.form-control {
  padding: 0.35rem 0.45rem;
  font-size: 0.8rem;
  min-width: 80px;
}

table.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  text-align: center;
  padding: 2.75rem 1.25rem;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 0.75rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 1.35rem;
  border: 1px solid var(--primary-border);
}

.empty-state p {
  margin-bottom: 0.9rem;
  max-width: 36ch;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-draft { background: #e8eef3; color: #4a5d6c; }
.badge-trial { background: var(--info-bg); color: var(--info); }
.badge-under-review { background: var(--warning-bg); color: var(--warning); }
.badge-approved { background: var(--success-bg); color: var(--success); }
.badge-rejected { background: var(--danger-bg); color: var(--danger); }
.badge-completed { background: var(--primary-light); color: var(--primary); }

.badge-beverage { background: #e8f3fb; color: #1a6fa8; }
.badge-namkeen { background: #fff1e0; color: #a35d10; }
.badge-pickle { background: #e6f6ee; color: #1f7a4c; }
.badge-makhan { background: #fce8f2; color: #a03d6d; }
.badge-other { background: #e8eef3; color: #4a5d6c; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: #fafbfc;
  padding: 0 0.25rem;
  scrollbar-width: thin;
}

.tab-btn {
  padding: 0.7rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
  font-size: 0.84rem;
  flex-shrink: 0;
}

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

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
  background: #fff;
}

.tab-short {
  display: none;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* ---------- Form / Detail pages ---------- */
.form-page-card,
.detail-page-card {
  margin-bottom: 0;
}

.form-page-heading h2,
.detail-page-heading h2 {
  margin: 0;
  word-break: break-word;
}

.form-page-sub {
  margin: 0.2rem 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.form-page-actions,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.form-page-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  gap: 0.5rem;
}

.form-page-footer .btn {
  min-width: 0;
}

.toolbar-hint {
  margin: 0;
  font-size: 0.78rem;
  flex: 1;
  min-width: 140px;
}

.table-scroll-hint {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Materials table: horizontal + vertical scroll when many rows */
#tab-ingredients .table-wrap {
  max-height: min(52vh, 440px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.ingredient-table {
  min-width: 320px;
}

#ingredientTable thead th {
  position: sticky;
  top: 0;
  z-index: 3;
}

#ingredientTable tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #f8fafc;
  box-shadow: 0 -1px 0 var(--border-soft);
}

#testTable {
  min-width: 560px;
}

.detail-page-body .table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.detail-page-body .detail-section .table-wrap:has(.ingredient-table) {
  max-height: min(52vh, 440px);
}

.detail-page-body .ingredient-table,
.detail-page-body .data-table {
  min-width: 640px;
}

/* ---------- Validation bar ---------- */
.validation-bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-top: 0.85rem;
  font-size: 0.84rem;
  font-weight: 500;
}

.validation-bar.valid {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #b5e4cb;
}

.validation-bar.incomplete {
  background: var(--warning-bg);
  color: #7a5200;
  border: 1px solid #f0dfa0;
}

.validation-bar.exceeded {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f5c2bc;
}

.validation-bar .val-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.validation-bar .val-item strong {
  font-size: 0.95rem;
}

/* ---------- Filters ---------- */
.filters-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.9rem;
  padding: 0.8rem;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters-row .form-group {
  min-width: 150px;
}

.filters-row .search-group {
  flex: 1;
  min-width: 200px;
}

/* ---------- Formula List ---------- */
.fl-page {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.fl-toolbar {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.fl-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.fl-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.fl-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.fl-filters {
  margin-bottom: 0;
  background: var(--bg);
}

.fl-table-panel {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.fl-table {
  min-width: 780px;
}

.fl-formula-cell strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.fl-formula-ids {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.fl-formula-ids code {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.7rem;
}

.fl-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.fl-actions .btn {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
}

.fl-cards {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}

.fl-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}

.fl-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.fl-card-title h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
}

.fl-card-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.fl-card-meta span {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
}

.fl-card-meta strong {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 0.1rem;
}

.fl-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.fl-card-actions .btn {
  width: 100%;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 52, 71, 0.35);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

.modal.modal-lg {
  max-width: 720px;
}

.modal.modal-xl {
  max-width: 960px;
}

.modal-header {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 30px;
  height: 30px;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text);
  background: var(--bg);
}

.modal-body {
  padding: 1.1rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  background: #fafbfc;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: none;
}

.toast {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.8rem 1rem;
  min-width: 270px;
  max-width: 390px;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  pointer-events: auto;
  animation: toastIn 0.2s ease;
  font-size: 0.84rem;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }

.toast.hiding {
  animation: toastOut 0.2s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-6px); }
}

.toast-icon {
  font-weight: 700;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }

.toast-msg {
  flex: 1;
  color: var(--text);
}

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1;
}

/* ---------- Detail view ---------- */
.detail-section {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.detail-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.85rem;
}

.detail-item label {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
  font-weight: 600;
}

.detail-item .value {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

.detail-item .value.notes {
  font-weight: 400;
  white-space: pre-wrap;
}

/* ---------- Data management ---------- */
.data-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.data-action-card-wide {
  grid-column: 1 / -1;
  min-height: 0;
}

.data-action-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: var(--shadow);
}

.data-action-card .dac-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.65rem;
  font-weight: 700;
}

.dac-icon-primary {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.dac-icon-success {
  background: var(--success-bg);
  color: var(--success);
}

.dac-icon-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.data-action-card h4 {
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--text);
  font-weight: 600;
}

.data-action-card p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
  flex: 1;
  line-height: 1.45;
}

.data-action-card .btn,
.data-action-card .btn-group {
  margin-top: auto;
}

.dm-section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0.25rem 0 0.65rem;
}

.dm-status {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.dm-status-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.dm-status-title h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.dm-status-sub {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dm-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.dm-status-pill.is-online {
  background: var(--success-bg);
  color: var(--success);
}

.dm-status-pill.is-offline {
  background: var(--danger-bg);
  color: var(--danger);
}

.dm-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.dm-status-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.dm-metric {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  min-width: 0;
}

.dm-metric-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.dm-metric-value {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.dm-metric-user {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-status-url {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  min-width: 0;
}

.dm-status-url code {
  font-size: 0.78rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  word-break: break-all;
}

.dm-trash-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.15rem 1.15rem;
  box-shadow: var(--shadow);
}

.dm-trash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.dm-trash-header h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.dm-trash-header p {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.storage-info {
  display: none;
}

.storage-info strong {
  color: var(--primary);
}

/* ---------- Recent list ---------- */
.recent-list {
  list-style: none;
}

.recent-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--transition);
  border-radius: 4px;
}

.recent-list li:hover {
  background: var(--primary-light);
}

.recent-list li:last-child {
  border-bottom: none;
}

.recent-info .name {
  font-weight: 600;
  color: var(--text);
  font-size: 0.88rem;
}

.recent-info .meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* ---------- Procedure steps ---------- */
.step-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.step-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  background: #fff;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 0.85rem;
  align-items: start;
}

.step-num {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
}

.step-content h4 {
  font-size: 0.86rem;
  margin-bottom: 0.3rem;
}

.step-meta {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.step-actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

/* ---------- Overlay ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(36, 52, 71, 0.3);
  z-index: 99;
}

.sidebar-overlay.open {
  display: block;
}

/* ---------- Utility ---------- */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* Compatibility aliases used by older rules */
:root {
  --gray-50: #fafbfc;
  --gray-100: #f0f3f6;
  --gray-200: #e8eef3;
  --gray-300: #d5dee7;
  --gray-400: #9aabba;
  --gray-500: #6b7c8c;
  --gray-600: #546678;
  --gray-700: #3d4f5f;
  --gray-800: #243447;
  --gray-900: #1a2733;
}

/* ---------- Print styles ---------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  html,
  body {
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  /* Hide entire app UI â€” prevents blank first page */
  body > *:not(#printArea) {
    display: none !important;
  }

  #printArea {
    display: block !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    opacity: 1 !important;
    z-index: auto !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }

  #printArea .formula-export-sheet {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  #printArea .page {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
    background: #fff !important;
  }

  #printArea .page h1 {
    font-size: 18pt !important;
    margin: 0 0 2px !important;
  }

  #printArea .page h2.sub {
    font-size: 14pt !important;
    margin: 0 0 10px !important;
  }

  #printArea .top-row {
    margin-bottom: 10px !important;
  }

  #printArea .section-title {
    margin: 10px 0 6px !important;
    font-size: 12pt !important;
  }

  #printArea .page table {
    font-size: 10pt !important;
    margin-bottom: 4px !important;
  }

  #printArea .page th,
  #printArea .page td {
    padding: 3px 5px !important;
  }

  #printArea .page ol {
    font-size: 10pt !important;
    margin: 0 0 4px !important;
  }

  #printArea .page ol li {
    margin-bottom: 2px !important;
  }

  #printArea .info-grid {
    font-size: 10pt !important;
    row-gap: 3px !important;
  }

  #printArea .note-box {
    font-size: 9pt !important;
    padding: 6px 8px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #printArea .outcome p {
    font-size: 10pt !important;
    margin: 2px 0 !important;
  }

  .trial-format .note-box {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ---------- PDF document (preview + print + export) ---------- */
.pdf-document {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 11px;
  color: #212529;
  background: #fff;
  line-height: 1.45;
}

.pdf-document * {
  box-sizing: border-box;
}

.pdf-top-bar {
  background: linear-gradient(180deg, #2dd4bf 0%, #14b8a6 100%);
  color: #fff;
  padding: 14px 18px;
  text-align: center;
  border-radius: 4px 4px 0 0;
}

.pdf-top-bar h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}

.pdf-top-bar p {
  margin: 0;
  font-size: 11px;
  opacity: 0.85;
}

.pdf-meta-strip {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-top: none;
  font-size: 10px;
}

.pdf-meta-strip strong {
  color: #212529;
}

.pdf-section {
  margin-top: 14px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  overflow: hidden;
  page-break-inside: avoid;
}

.pdf-section-head {
  background: linear-gradient(180deg, #fff 0%, #f1f3f5 100%);
  border-bottom: 1px solid #dee2e6;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #212529;
}

.pdf-section-body {
  padding: 12px;
}

.pdf-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 14px;
}

.pdf-info-item label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  color: #6c757d;
  margin-bottom: 2px;
  letter-spacing: 0.04em;
}

.pdf-info-item span {
  font-size: 11px;
  font-weight: 600;
  color: #212529;
}

.pdf-info-item.full {
  grid-column: 1 / -1;
}

.pdf-notes {
  margin-top: 10px;
  padding: 8px 10px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 4px;
  font-size: 10px;
  white-space: pre-wrap;
}

.pdf-table-wrap {
  border: 1px solid #99f6e4;
  border-radius: 4px;
  overflow: hidden;
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}

.pdf-table th,
.pdf-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #dee2e6;
  border-right: 1px solid #e9ecef;
  vertical-align: middle;
}

.pdf-table th:last-child,
.pdf-table td:last-child {
  border-right: none;
}

.pdf-table thead th {
  background: linear-gradient(180deg, #2dd4bf 0%, #14b8a6 100%);
  color: #fff;
  font-weight: 700;
  font-size: 10px;
  border-bottom: 1px solid #0d9488;
  border-right: 1px solid rgba(255, 255, 255, 0.28);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pdf-table tbody tr:nth-child(even) {
  background: #f8f9fa;
}

.pdf-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.pdf-table td.num-highlight {
  background: #f1f3f5;
}

.pdf-table tfoot td {
  background: linear-gradient(180deg, #14b8a6 0%, #0d9488 100%);
  color: #fff;
  font-weight: 700;
  border-top: 2px solid #0f766e;
  border-right: 1px solid rgba(255, 255, 255, 0.28);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pdf-table tfoot td.num {
  text-align: right;
}

.pdf-validation {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.pdf-validation.valid {
  background: #d1e7dd;
  color: #0f5132;
  border: 1px solid #a3cfbb;
}

.pdf-validation.warn {
  background: #fff3cd;
  color: #664d03;
  border: 1px solid #ffecb5;
}

.pdf-validation.bad {
  background: #f8d7da;
  color: #842029;
  border: 1px solid #f5c2c7;
}

.pdf-document-footer {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px solid #adb5bd;
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #6c757d;
}

.pdf-preview-modal .modal-body {
  background: #eef6f5;
}

.pdf-preview-body {
  padding: 1rem;
}

.pdf-preview-body .formula-export-sheet {
  max-width: 100%;
  margin: 0 auto;
}

/* ========== R&D Trial Record â€” same as Downloads/pdf/index.html ========== */
.trial-format {
  background: transparent;
  color: #111;
  border: none;
  padding: 0;
  box-sizing: border-box;
}

.trial-format .page {
  --ink: #111111;
  --line: #000000;
  --note-border: #2e7d4f;
  --bg: #ffffff;
  max-width: 850px;
  width: 100%;
  margin: 0 auto;
  background: var(--bg);
  padding: 28px 36px 32px;
  border: 1px solid #ccc;
  box-sizing: border-box;
  font-family: "Times New Roman", Times, Georgia, serif;
  color: var(--ink);
}

.trial-format .page * {
  box-sizing: border-box;
}

.trial-format .page h1 {
  text-align: center;
  font-size: 22px;
  margin: 0 0 2px;
  font-weight: bold;
  font-family: inherit;
}

.trial-format .page h2.sub {
  text-align: center;
  font-size: 17px;
  margin: 0 0 20px;
  font-weight: bold;
  font-family: inherit;
  text-decoration: none;
  background: none;
  color: #111;
  padding: 0;
}

.trial-format .top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.trial-format .top-left p {
  margin: 2px 0;
  font-size: 14px;
}

.trial-format .note-box {
  border: 1.5px solid #2e7d4f;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: bold;
  max-width: 320px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.trial-format .section-title {
  font-size: 15px;
  font-weight: bold;
  margin: 14px 0 8px;
  background: none;
  color: #111;
  padding: 0;
}

.trial-format .info-grid {
  display: grid;
  grid-template-columns: 150px 1fr 170px 1fr;
  row-gap: 6px;
  font-size: 14px;
  margin-bottom: 6px;
}

.trial-format .info-grid .label {
  font-weight: bold;
}

.trial-format .info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-bottom: 6px;
}

.trial-format .info-table th,
.trial-format .info-table td {
  border: none !important;
  padding: 3px 8px 3px 0;
  text-align: left;
  vertical-align: top;
  background: transparent;
}

.trial-format .info-table th {
  width: 140px;
  font-weight: bold;
  white-space: nowrap;
}

.trial-format .page table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-bottom: 8px;
  table-layout: auto;
}

.trial-format .page th,
.trial-format .page td {
  border: 1px solid #000;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  background: #fff;
  color: #111;
  font-weight: normal;
}

.trial-format .page th {
  font-weight: bold;
}

.trial-format .page ol {
  margin: 0 0 8px;
  padding-left: 26px;
  font-size: 14px;
}

.trial-format .page ol li {
  margin-bottom: 6px;
}

.trial-format .outcome p {
  margin: 4px 0;
  font-size: 14px;
}

.trial-format .outcome b {
  font-weight: bold;
}

.pdf-preview-body {
  padding: 1rem;
  overflow: auto;
  max-height: 75vh;
  background: #eef6f5;
}

.pdf-preview-body .trial-format .page {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

/* Hidden print/PDF source â€” never off-screen (fixes html2canvas clipping) */
#printArea {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: 850px;
  max-width: 100%;
  padding: 0;
  background: #fff;
  z-index: -9999;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

#printArea.capture-ready {
  display: block !important;
  /* Full opacity required — html2canvas fails / blanks with opacity ~0 */
  opacity: 1 !important;
  visibility: visible !important;
  z-index: 1;
  overflow: visible;
  pointer-events: none;
}

#printArea .formula-export-sheet {
  width: 100%;
  border: none;
  box-shadow: none;
  background: #fff;
}

#printArea .page {
  width: 850px;
  max-width: 850px;
  border: none;
  box-shadow: none;
  margin: 0;
}

body.printing-formula #printArea {
  display: block !important;
  position: static !important;
  opacity: 1 !important;
  z-index: auto !important;
  width: 100% !important;
  max-width: none !important;
  pointer-events: auto;
}

body.printing-formula #printArea .page {
  width: 100% !important;
  max-width: none !important;
  margin: 0 auto !important;
  border: none !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .dm-status-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-page-header .desktop-actions {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .form-grid,
  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-area {
    padding: 0.85rem;
  }

  .step-card {
    grid-template-columns: 40px 1fr;
  }

  .step-actions {
    grid-column: 1 / -1;
  }

  .header {
    padding: 0 0.85rem;
    height: auto;
    min-height: var(--header-h);
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .user-chip {
    margin-right: 0;
    max-width: 100%;
  }

  .user-chip-name {
    max-width: 140px;
  }

  .page-title {
    font-size: 1rem;
  }

  .page-subtitle {
    display: none;
  }

  .filters-row,
  .fl-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filters-row .form-group,
  .filters-row .search-group {
    min-width: 0;
    width: 100%;
  }

  .fl-table-panel {
    display: none;
  }

  .fl-cards {
    display: flex;
  }

  .fl-toolbar-top {
    align-items: stretch;
  }

  .fl-toolbar-top .btn {
    width: 100%;
  }

  .fl-toolbar-top > div {
    width: 100%;
  }

  .fl-card-actions {
    grid-template-columns: 1fr 1fr;
  }

  .data-actions-grid {
    grid-template-columns: 1fr;
  }

  .dm-status-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .dm-trash-header {
    flex-direction: column;
  }

  .dm-trash-header .btn-group {
    width: 100%;
  }

  .dm-trash-header .btn-group .btn {
    flex: 1;
  }

  #trashTableWrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .card-header {
    padding: 0.85rem 0.9rem;
  }

  .card-body {
    padding: 0.9rem;
  }

  .card-footer {
    padding: 0.75rem 0.9rem;
  }

  .card-header .btn-group {
    width: 100%;
    flex-wrap: wrap;
  }

  .card-header .btn-group .btn {
    flex: 1 1 auto;
  }

  /* Create / Edit form */
  .form-page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .form-page-header .desktop-actions {
    display: none;
  }

  .form-page-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .form-page-footer #btnSaveFormula2 {
    grid-column: 1 / -1;
  }

  .form-page-footer .btn {
    width: 100%;
  }

  .tab-full {
    display: none;
  }

  .tab-short {
    display: inline;
  }

  .tab-btn {
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .spacer {
    display: none;
  }

  .toolbar .btn {
    width: 100%;
  }

  #tab-ingredients .table-wrap,
  .detail-page-body .detail-section .table-wrap:has(.ingredient-table) {
    max-height: min(48vh, 360px);
  }

  .validation-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  /* Details view */
  .detail-page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .detail-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .detail-actions .btn {
    width: 100%;
  }

  .detail-actions #btnBackToList,
  .detail-actions #btnEditFromView,
  .detail-actions #btnDeleteFromView {
    grid-column: auto;
  }

  .detail-actions #btnDownloadPdf {
    grid-column: 1 / -1;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-section {
    padding: 0.85rem;
  }

  .login-card {
    padding: 1.5rem 1.15rem 1.25rem;
  }

  .modal {
    margin: 0.75rem;
    max-height: calc(100vh - 1.5rem);
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .dm-status-metrics {
    grid-template-columns: 1fr;
  }

  .btn-group {
    width: 100%;
    flex-wrap: wrap;
  }

  .header-right #headerCreateBtn {
    flex: 1;
  }

  .dm-status-url {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-page-footer {
    grid-template-columns: 1fr;
  }

  .form-page-footer #btnSaveFormula2 {
    grid-column: auto;
    order: -1;
  }

  .detail-actions {
    grid-template-columns: 1fr;
  }

  .fl-card-actions {
    grid-template-columns: 1fr;
  }
}
