@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap");

:root {
  --bg0: #070b17;
  --bg1: #0b1226;

  --panel: rgba(10, 16, 35, 0.62);
  --panel2: rgba(9, 14, 30, 0.72);

  --stroke: rgba(255, 255, 255, 0.10);
  --stroke2: rgba(255, 255, 255, 0.16);

  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.65);

  --accent: #6d5efc;
  --accent2: #2f86ff;
  --danger: #ff4d6d;

  --shadow: 0 18px 55px rgba(0, 0, 0, 0.55);

  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* =========================
   APP PAGES (index/master)
   ========================= */
body.page-app {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(109, 94, 252, 0.22), transparent 55%),
    radial-gradient(900px 600px at 85% 15%, rgba(47, 134, 255, 0.14), transparent 55%),
    radial-gradient(1000px 700px at 50% 95%, rgba(109, 94, 252, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  padding: 26px;
  visibility: hidden;
  /* will be set visible after auth */
}

/* Loader */
#loader {
  max-width: 1240px;
  margin: 0 auto 14px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
}

#loader::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: rgba(255, 255, 255, 0.85);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* NAVBAR */
.app-header {
  position: sticky;
  margin-bottom: 18px;
  top: 0;
  z-index: 999;
  backdrop-filter: blur(10px);
  background: rgba(6, 10, 24, 0.55);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-link,
.nav-link:visited {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: 0.15s ease;
  font-weight: 500;
}

.nav-link:hover {
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.nav-active {
  color: #ffffff;
  background: rgba(120, 110, 255, 0.18);
  border-color: rgba(120, 110, 255, 0.35);
}

.nav-logout {
  appearance: none;
  border: 6px none;
  padding: 10px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;

  color: #fff;
  background: linear-gradient(135deg, #6f7bff 0%, #5865f2 55%, #4b5bff 100%);

  box-shadow:
    0 10px 22px rgba(88, 101, 242, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);

  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.nav-logout:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow:
    0 14px 28px rgba(88, 101, 242, 0.40),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.nav-logout:active {
  transform: translateY(0);
  filter: brightness(0.98);
  box-shadow:
    0 8px 16px rgba(88, 101, 242, 0.30),
    inset 0 2px 8px rgba(0, 0, 0, 0.18);
}

.nav-logout:focus-visible {
  outline: 3px solid rgba(111, 123, 255, 0.45);
  outline-offset: 3px;
}

/* Main content shell */
#mainContent,
.page-app .content-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
}

h1 {
  text-align: center;
  margin: 10px 0 20px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2.2px;
  text-transform: uppercase;
}

/* Top navigation (index) */
.top-nav,
.nav-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.top-nav a,
.nav-buttons a,
.top-nav button,
.nav-buttons button,
button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 90ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.top-nav a:hover,
.nav-buttons a:hover,
button:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.25);
}

.top-nav a:active,
.nav-buttons a:active,
button:active {
  transform: translateY(1px);
}

#logoutBtn,
.delete-btn {
  border-color: rgba(255, 77, 109, 0.35);
  background: rgba(255, 77, 109, 0.14);
}

#logoutBtn:hover,
.delete-btn:hover {
  background: rgba(255, 77, 109, 0.18);
}

/* Sections (cards) */
.form-section,
.table-section,
.summary-section,
.action-buttons,
.section {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  border-radius: var(--radius-xl);
  padding: 18px;
  margin-bottom: 16px;
}

/* Form rows */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.form-row label {
  width: 160px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

/* Inputs/selects */
input,
select,
textarea {
  flex: 1;
  min-width: 240px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  outline: none;
  font-size: 13px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(109, 94, 252, 0.55);
  box-shadow: 0 0 0 4px rgba(109, 94, 252, 0.18);
  background: rgba(255, 255, 255, 0.09);
}

input[readonly] {
  opacity: 0.9;
}

/* Table */
.table-section {
  overflow: auto;
}

table {
  table-layout: fixed;
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  border-spacing: 0;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

/* Column widths (edit these numbers) */
table th:nth-child(1),
table td:nth-child(1) {
  width: 60px;
}

/* Sr No */
table th:nth-child(2),
table td:nth-child(2) {
  width: 180px;
}

/* S.O.R No */
table th:nth-child(3),
table td:nth-child(3) {
  width: 280px;
}

/* Description */
table th:nth-child(4),
table td:nth-child(4) {
  width: 120px;
}

/* Unit */
table th:nth-child(5),
table td:nth-child(5) {
  width: 150px;
}

/* Size */
table th:nth-child(6),
table td:nth-child(6) {
  width: 100px;
}

/* Qty */
table th:nth-child(7),
table td:nth-child(7) {
  width: 120px;
}

/* Rate */
table th:nth-child(8),
table td:nth-child(8) {
  width: 140px;
}

/* Amount */

thead th {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.86);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.6px;
  overflow: hidden;
  /* ok for headers */
  text-overflow: ellipsis;
  white-space: nowrap;
}

th,
td {
  border: 1px solid rgba(255, 255, 255, 0.10);
  padding: 10px;
  text-align: center;
  white-space: nowrap;
  /* IMPORTANT: do NOT hide overflow here, it clips rounded inputs */
  overflow: visible;
}

tbody td {
  color: rgba(255, 255, 255, 0.85);
}

/* Make table controls fit perfectly inside cells (fixes Unit/Size cut) */
table td input,
table td select,
table td textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
  box-sizing: border-box;
  /* KEY */
  padding: 8px 10px;
  border-radius: 10px;
  margin: 0;
  /* no auto-centering weirdness */
}

/* If you want ellipsis ONLY for plain text cells (not inputs),
   you can apply it to a wrapper span later. For now, keep safe behavior. */

tr.selected {
  background: rgba(47, 134, 255, 0.10);
}

/* Action buttons */
.action-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.action-buttons button {
  background: linear-gradient(90deg, rgba(109, 94, 252, 0.40), rgba(47, 134, 255, 0.26));
  border-color: rgba(255, 255, 255, 0.18);
}

.action-buttons button:hover {
  background: linear-gradient(90deg, rgba(109, 94, 252, 0.52), rgba(47, 134, 255, 0.34));
}

/* Master page table */
#masterPreviewTable {
  min-width: 900px;
}

/* Slightly smaller on narrow screens */
@media (max-width: 720px) {
  body.page-app {
    padding: 18px;
  }

  .form-row label {
    width: 120px;
  }

  input,
  select,
  textarea {
    min-width: 180px;
  }

  table {
    min-width: 760px;
  }
}

/* =========================
   LOGIN PAGE
   ========================= */
body.page-login {
  /* login.html keeps its own inline styles; this prevents accidental global overrides */
  visibility: visible;
}

/* Dark dropdown options fix */
:root {
  color-scheme: dark;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

select option,
select optgroup {
  background-color: #0b1220;
  color: var(--text);
}

select option:disabled {
  color: rgba(255, 255, 255, 0.55);
}

select option:checked {
  background-color: rgba(99, 102, 241, 0.35);
  color: #ffffff;
}

/* ===== FIX: Master Data table column shrinking ===== */
#masterPreviewTable {
  width: 100%;
  min-width: 0;
  /* remove forced wide table */
  table-layout: auto;
  /* let columns size naturally */
}

/* allow master table to show full text properly */
#masterPreviewTable th,
#masterPreviewTable td {
  overflow: visible;
  text-overflow: initial;
}

/* Category column: give it room + allow wrapping */
#masterPreviewTable th:nth-child(1),
#masterPreviewTable td:nth-child(1) {
  width: 260px;
  /* adjust as you want */
  white-space: normal;
  /* wrap long category names */
}

/* SOR No column: keep neat */
#masterPreviewTable th:nth-child(2),
#masterPreviewTable td:nth-child(2) {
  width: 140px;
  /* adjust as you want */
  white-space: nowrap;
}