/* ========================================
   CSS CUSTOM PROPERTIES (DESIGN TOKENS)
   ======================================== */
:root {
  --bg: #020609;
  --bg-alt: #050b10;
  --card-bg: #050d11;
  --fg: #f5fff8;
  --muted: #7a8f8a;
  --accent: #00ff9a;
  --accent-muted: #0d6040;
  --danger: #ff4d4f;
  --border: rgba(0, 255, 154, 0.16);
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.9);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --grid-gap: 1.25rem;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  --scrollbar-track: rgba(0, 0, 0, 0.3);
  --scrollbar-thumb: rgba(0, 255, 154, 0.35);
  --scrollbar-thumb-hover: rgba(0, 255, 154, 0.65);
}

/* ========================================
   GLOBAL RESET
   ======================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: radial-gradient(circle at top, #04151c 0, #010307 55%, #000000 100%);
  color: var(--fg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ========================================
   GLOBAL INPUT/SELECT/TEXTAREA RESET
   Strip ALL default borders/backgrounds so
   .input-row is the sole visual container
   ======================================== */
input,
select,
textarea {
  background: transparent;
  color: var(--fg);
  border: none;
  border-radius: 0;
  padding: 0.25rem 0.45rem;
  font-size: 0.75rem;
  outline: none;
  box-shadow: none;
  width: 100%;
  font-family: var(--font-sans);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: none;
  border: none;
}

textarea {
  resize: none;
  min-height: 1.8rem;
  max-height: 3rem;
}

/* ========================================
   THIN SCROLLBAR — only form + table
   ======================================== */
.matrix-form::-webkit-scrollbar,
.table-wrapper::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.matrix-form::-webkit-scrollbar-track,
.table-wrapper::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 999px;
}
.matrix-form::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
}
.matrix-form::-webkit-scrollbar-thumb:hover,
.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}
.matrix-form,
.table-wrapper {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* Hide scrollbars everywhere else */
body::-webkit-scrollbar,
.app-shell::-webkit-scrollbar,
.panel::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* ========================================
   MATRIX BACKGROUND
   ======================================== */
.matrix-bg {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(
      rgba(0, 0, 0, 0.86),
      rgba(0, 0, 0, 0.98)
    ),
    repeating-linear-gradient(
      to bottom,
      rgba(0, 255, 153, 0.1) 0,
      rgba(0, 255, 153, 0.1) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(circle at 10% 20%, rgba(0, 255, 153, 0.22) 0, transparent 55%),
    radial-gradient(circle at 90% 80%, rgba(0, 153, 255, 0.18) 0, transparent 60%);
  pointer-events: none;
  z-index: -1;
}

/* ========================================
   APP SHELL
   ======================================== */
.app-shell {
  position: relative;
  margin: 0;
  padding: 0.75rem;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at top left, #071b21 0, #020609 60%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========================================
   HEADER
   ======================================== */
.app-header {
  flex: 0 0 auto;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(0, 255, 154, 0.16);
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(14px);
  background: linear-gradient(
    to right,
    rgba(0, 10, 10, 0.9),
    rgba(0, 15, 18, 0.95)
  );
}

.logo-lockup {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(0, 255, 154, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 0 12px rgba(0, 255, 154, 0.6);
}

.logo-title {
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 0.9rem;
  text-transform: uppercase;
}

.logo-subtitle {
  font-size: 0.7rem;
  color: var(--muted);
}

/* ========================================
   MAIN LAYOUT
   ======================================== */
.app-main {
  flex: 1 1 auto;
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.4fr);
  gap: var(--grid-gap);
  height: calc(100vh - 80px);
  min-height: 0;
  overflow: hidden;
}

/* ========================================
   PANELS
   ======================================== */
.panel {
  background: radial-gradient(circle at top left, #07141a 0, #020609 60%);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(0, 255, 154, 0.16);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.85);
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.panel-title {
  flex: 0 0 auto;
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ========================================
   PANEL TITLE ROW
   ======================================== */
.panel-title-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.panel-title-row .panel-title {
  margin: 0;
}

/* Copy-all button */
.copy-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.68rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 255, 154, 0.25);
  background: transparent;
  color: rgba(0, 255, 154, 0.3);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.copy-all-btn svg {
  stroke: rgba(0, 255, 154, 0.3);
  transition: stroke 0.2s;
}

.copy-all-btn:hover {
  color: var(--accent);
  border-color: rgba(0, 255, 154, 0.8);
  background: rgba(0, 255, 154, 0.08);
  box-shadow: 0 0 8px rgba(0, 255, 154, 0.3);
}

.copy-all-btn:hover svg {
  stroke: var(--accent);
}

/* ========================================
   LEFT PANEL: FORM
   ======================================== */
.matrix-form {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.4rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 0.5rem;
}

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

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

label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

/* ========================================
   INPUT ROW — the SOLE visual container
   Input + icon live inside this box.
   No border/bg on the input itself.
   ======================================== */
.input-row {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.55);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 255, 154, 0.22);
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;        /* clip children to rounded corners */
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 255, 154, 0.35);
}

/* Input fills the row — no own border, no own bg */
.input-row input,
.input-row select,
.input-row textarea {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  padding: 0.28rem 0.3rem 0.28rem 0.45rem;
  font-size: 0.75rem;
  color: var(--fg);
  width: auto;
}

/* Textarea variant */
.input-row-textarea {
  align-items: flex-start;
}

.input-row-textarea textarea {
  min-height: 1.8rem;
  max-height: 3rem;
  resize: none;
}

/* ========================================
   COPY FIELD BUTTON
   Lives INSIDE .input-row at the right edge.
   Subdued matrix green by default,
   bright matrix green on hover.
   ======================================== */
.copy-field-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-right: 3px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  /* SVG stroke color — subdued green, NOT white */
  color: rgba(0, 255, 154, 0.22);
  transition: color 0.18s, background 0.18s, box-shadow 0.18s;
}

/* Force SVG to inherit the green color */
.copy-field-btn svg {
  stroke: currentColor;
  fill: none;
  display: block;
}

.copy-field-btn:hover {
  color: var(--accent);
  background: rgba(0, 255, 154, 0.1);
  box-shadow: 0 0 6px rgba(0, 255, 154, 0.4);
}

/* Textarea copy button aligns to top */
.copy-field-btn-textarea {
  align-self: flex-start;
  margin-top: 3px;
}

/* Form actions pinned at bottom */
.form-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
  padding-top: 0.3rem;
  border-top: 1px solid rgba(0, 255, 154, 0.1);
}

/* ========================================
   BUTTONS
   ======================================== */
.btn-primary,
.btn-secondary,
.btn-ghost {
  font-size: 0.72rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 255, 154, 0.4);
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, rgba(0, 255, 154, 0.95), rgba(0, 190, 255, 0.9));
  color: #000;
  border-color: transparent;
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  border-color: rgba(0, 255, 154, 0.3);
  color: var(--accent);
}

.btn-secondary:hover { background: rgba(0, 255, 154, 0.1); }

.btn-ghost {
  border-color: rgba(0, 255, 154, 0.25);
  color: var(--muted);
}

.btn-ghost:hover {
  border-color: rgba(0, 255, 154, 0.6);
  color: var(--accent);
}

.btn-danger {
  border-color: rgba(255, 77, 79, 0.8);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(60, 0, 0, 0.9);
  box-shadow: 0 0 10px rgba(255, 77, 79, 0.7);
}

/* ========================================
   RIGHT PANEL HEADER
   ======================================== */
.panel-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

.panel-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.search-input {
  min-width: 0;
  flex: 1 1 150px;
  /* search input needs its own border since it's not in .input-row */
  background: rgba(0,0,0,0.5) !important;
  border: 1px solid rgba(0, 255, 154, 0.22) !important;
  border-radius: var(--radius-sm) !important;
  padding: 0.25rem 0.45rem !important;
}

.search-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 1px rgba(0, 255, 154, 0.35) !important;
}

.filter-select {
  width: 130px;
  background: rgba(0,0,0,0.5) !important;
  border: 1px solid rgba(0, 255, 154, 0.22) !important;
  border-radius: var(--radius-sm) !important;
  padding: 0.25rem 0.45rem !important;
}

.filter-select:focus {
  border-color: var(--accent) !important;
}

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

/* ========================================
   TABLE WRAPPER
   ======================================== */
.table-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 255, 154, 0.18);
  background: radial-gradient(circle at top left, #07141a 0, #020609 60%);
  overflow: auto;
}

/* ========================================
   TABLE
   ======================================== */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.72rem;
}

.matrix-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(
    to right,
    rgba(0, 12, 10, 0.98),
    rgba(0, 20, 18, 0.98)
  );
}

.resizable-th {
  position: relative;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid rgba(0, 255, 154, 0.12);
  text-align: left;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  resize: horizontal;
}

.matrix-table th,
.matrix-table td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid rgba(0, 255, 154, 0.08);
  vertical-align: top;
}

/* Category (col 1) and Price (col 3): normal size */
.matrix-table tbody td:nth-child(1),
.matrix-table tbody td:nth-child(3) {
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* All other columns: small font, wrapping */
.matrix-table tbody td:nth-child(2),
.matrix-table tbody td:nth-child(4),
.matrix-table tbody td:nth-child(5),
.matrix-table tbody td:nth-child(6),
.matrix-table tbody td:nth-child(7),
.matrix-table tbody td:nth-child(8) {
  font-size: 0.8rem;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.3;
}

.matrix-table tbody tr {
  transition: background 0.12s ease-out;
  cursor: pointer;
}

.matrix-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.38);
}

.matrix-table tbody tr:hover {
  background: rgba(0, 80, 40, 0.85);
}

tbody tr.selected-row {
  background: rgba(0, 100, 60, 0.9) !important;
}

.category-cell {
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline;
}

.category-cell:hover {
  color: #00ffcc;
}

/* ========================================
   TOTALS BAR
   ======================================== */
.totals-bar {
  flex: 0 0 auto;
  margin-top: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  background: rgba(0, 255, 153, 0.06);
  border: 1px solid rgba(0, 255, 153, 0.4);
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.85rem;
}

/* ========================================
   BADGES
   ======================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  font-size: 0.45rem;
  border: 1px solid transparent;
}

.badge-none {
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--muted);
}

.badge-extended {
  border-color: rgba(0, 255, 154, 0.6);
  color: var(--accent);
}

/* ========================================
   MODAL
   ======================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 40;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.hidden,
.modal-backdrop.hidden {
  display: none;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 10px;
  border: 1px solid var(--accent-muted);
  padding: 0.9rem 1rem;
  width: min(420px, 90vw);
  max-height: 60vh;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.modal-title {
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--accent);
}

#notes-textarea {
  width: 100%;
  margin-top: 0.2rem;
  margin-bottom: 0.6rem;
  background: rgba(0, 0, 0, 0.4) !important;
  border-radius: 6px;
  border: 1px solid var(--accent-muted) !important;
  color: var(--fg);
  resize: none;
  min-height: 4rem;
  max-height: 7rem;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  float: right;
  font-size: 1.1rem;
  cursor: pointer;
}

.modal-close:hover { color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

/* ========================================
   COPY TOAST
   ======================================== */
.copy-toast {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  background: rgba(0, 255, 154, 0.1);
  border: 1px solid rgba(0, 255, 154, 0.5);
  color: var(--accent);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.75rem;
  z-index: 999;
  pointer-events: none;
}

.copy-toast.hidden {
  display: none;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 980px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    overflow-y: auto;
  }

  .panel {
    height: auto;
    max-height: 80vh;
  }

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

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

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