:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

/* Light/Dark theme tokens */
:root.theme-dark {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #22c55e;
}

:root.theme-light {
  --bg: #f7fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --accent: #0ea5e9;
  --accent-2: #16a34a;
}

:root.theme-light thead th {
  background: #f3f4f6 !important;
  color: #222 !important;
}
:root.theme-dark thead th {
  background: #23272f !important;
  color: #f3f4f6 !important;
}

/* RTL helper for Hebrew (applied via JS when lang is he) */
.rtl { direction: rtl; }

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}
.hidden{
  display: none;
}

body {
  margin: 0;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.12), transparent 28%),
    radial-gradient(circle at top left, rgba(34, 197, 94, 0.08), transparent 22%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.container {
  width: min(1440px, calc(100% - 32px));
  margin: 24px auto 40px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.title-wrap h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0.3px;
}

.title-wrap p {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 900px;
  line-height: 1.5;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 20px;
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.01));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(255, 255, 255, 0.02);
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
}

.panel-header p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.panel-body {
  padding: 20px 24px 24px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  transition: transform 0.05s, border-color 0.2s, background 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.45);
}

.btn.success {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.45);
}

.btn.warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.45);
}

.btn.danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.45);
}

.icon-btn {
  min-width: 42px;
  min-height: 42px;
  padding: 10px;
  gap: 0;
}

.action-icon-btn {
  min-width: 38px;
  min-height: 38px;
  padding: 8px;
  gap: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 16px;
  padding: 16px;
}

.stat .kicker {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.stat .value {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 800;
}

.stat .sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.split-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.split-header h3 {
  margin: 0;
}

.search {
  max-width: 360px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  outline: none;
}

.table-wrap {
  overflow: auto;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1320px;
  background: rgba(255,255,255,.01);
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

/* --- Added: header & sort-button visual polish --- */
/* Make header band slightly richer and add padding for sort area */
th {
  background: linear-gradient(180deg, #07101a 0%, #182233 100%);
  padding: 14px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  font-weight: 700;
  letter-spacing: 0.7px;
}

/* Sort button inside table headers (persistent icon + label) */
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 12px;
}

.sort-btn:focus { outline: 2px solid rgba(56,189,248,0.12); outline-offset: 2px; }

/* Small caret/arrow icon next to the label. Use Bootstrap icons classes (bi) already in markup */
.sort-btn .sort-icon {
  font-size: 12px;
  opacity: 0.75;
  transition: transform .16s ease, opacity .12s ease, color .12s ease;
  display: inline-block;
  line-height: 1;
}

/* Directional state helpers: app.js adds .asc/.desc/.active to the button */
.sort-btn.asc .sort-icon { transform: rotate(180deg); }
.sort-btn.desc .sort-icon { transform: rotate(0deg); }

/* Active sort visual (highlighted background & accent color) */
.sort-btn.active {
  background: rgba(56, 189, 248, 0.06);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.12);
}
.sort-btn.active .sort-icon { opacity: 1; color: var(--accent); }

/* Ensure the icon size and spacing look balanced next to header label */
th .sort-btn i { font-size: 14px; }

/* Ended spool visuals: prefer a class but also catch inline opacity used elsewhere */
tr.ended-row,
tr[style*="opacity:0.5"] {
  opacity: 0.5;
  color: var(--muted);
}
tr.ended-row td { text-decoration: line-through; }

/* Disabled action buttons (for ended spools) should look visually inactive */
.btn[disabled],
.action-icon-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(20%);
}

/* Small tweak: tighten table header font-weight and spacing for nicer look */
th {
  font-weight: 700;
  letter-spacing: 0.7px;
}

/* Make sure table min-width still respected on small screens */
@media (max-width: 720px) {
  table { min-width: 900px; }
}

/* end of added styles */

tr:hover td {
  background: rgba(255,255,255,.02);
}

/* Tabs container: keep it visually grouped under header */
#tabsContainer {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  align-items: center;
  /* ensure it sits above panels and isn't pushed by flex quirks */
  position: relative;
  z-index: 2;
}

/* Make the tabs visually consistent with toolbar */
#tabsContainer .btn { padding: 10px 14px; }

@media (max-width: 720px) {
  #tabsContainer { gap: 6px; }
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(255,255,255,.03);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.25);
  background: var(--c, #9ca3af);
  flex: none;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.compact {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.highlight {
  color: var(--accent);
  font-weight: 800;
}

.status-low {
  color: #fca5a5;
}

.status-ok {
  color: #86efac;
}

.status-mid {
  color: #fcd34d;
}

.footer-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-row-2 {
  grid-template-columns: repeat(2, 1fr);
}

.field-row-3 {
  grid-template-columns: repeat(3, 1fr);
}
.field-row-4 {
  grid-template-columns: repeat(4, 1fr);
}

#quantity {width: 80px;}
#spoolWeight {width: 115px;}

label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.2px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.hint {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.18);
  color: #dbeafe;
  line-height: 1.45;
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  z-index: 1000;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-dialog {
  width: min(100%, 820px);
  background: linear-gradient(180deg, #111827, #0f172a);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
  transform: translateY(72px) scale(0.98);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(.2,.8,.2,1), opacity 0.32s ease;
}

.modal.is-open .modal-dialog {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.modal-title-wrap h2 {
  margin: 0;
  font-size: clamp(22px, 3vw, 28px);
}

.modal-title-wrap p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.modal-close {
  flex: none;
}

.modal-body {
  padding: 20px 24px 24px;
}

.modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  background: rgba(56, 189, 248, 0.08);
  color: #dbeafe;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 14px;
}

.modal-form-no-scroll .modal-dialog {
  overflow: hidden;
}

/* Header controls container */
#headerControls {
  position: absolute;
  right: 20px;
  top: 18px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 3;
}

/* For Hebrew (RTL), the .rtl class will flip the header controls to the left */
.rtl #headerControls {
  right: auto;
  left: 20px;
}

#headerControls select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 10px;
}

#headerControls #themeToggleBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 8px;
  border-radius: 10px;
}

#headerControls #themeToggleBtn i {
  font-size: 18px;
}

#headerControls select option {
  padding: 6px 8px;
  padding-left: 28px;
}

/* Style the small flag icon span */
#headerControls .lang-flag {
  display: inline-flex;
  width: 22px;
  height: 16px;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
}

#headerControls .lang-flag img {
  width: 22px;
  height: 16px;
  display: block;
}

/* RTL flip for flag margin */
.rtl #headerControls .lang-flag {
  margin-right: 0;
  margin-left: 6px;
}

#colorHex{
    height: 55px!important;
    width: 100px!important;
}

/* Small responsive tweak */
@media (max-width: 520px) {
  #headerControls .lang-flag {
    display: none;
  }
}

/* On hover for icon */
#headerControls #themeToggleBtn:hover {
  border-color: var(--accent);
}

/* keep flags visible in select on Windows/Chromium; fallback to text if emoji not available */
#headerControls select::-ms-expand {
  display: none;
}

@media (max-width: 720px) {
  #headerControls { right: 12px; top: 12px; }
}

@media (max-width: 1100px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .container {
    width: min(100% - 16px, 1440px);
    margin: 16px auto 24px;
  }

  .field-row,
  .field-row-3 {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar .btn {
    flex: 1;
  }

  .modal {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-dialog {
    width: 100%;
    border-radius: 22px 22px 0 0;
  }

  .modal-header,
  .modal-body,
  .panel-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  table { min-width: 900px; }
}

@media (max-width: 420px) {
  .title-wrap h1 {
    font-size: 24px;
  }

  .btn {
    padding: 10px 12px;
    font-size: 13px;
  }

  th,
  td {
    padding: 10px 12px;
  }
}