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

:root{
  --bg: #0b1216;
  --bg2: #0a1b22;
  --card: #121a1f;
  --card2: rgba(255,255,255,.04);
  --text: #f1f5f9;
  --muted: #9aa6b2;
  --border: rgba(255,255,255,.08);
  --topbar-bg: rgba(10,18,20,.7);
  --topbar-border: rgba(255,255,255,.08);
  --nav-text: var(--muted);
  --nav-active-bg: rgba(37,194,160,.15);
  --nav-active-border: rgba(37,194,160,.30);
  --nav-hover-bg: rgba(14,165,233,.12);
  --nav-hover-border: rgba(14,165,233,.25);
  --accent: #25c2a0;
  --accent-2: #0ea5e9;
  --accent-ink: #042f2e;
  --danger: #ef4444;
  --dangerText: #fecaca;
  --dangerBg: rgba(239,68,68,.12);
  --dangerBorder: rgba(239,68,68,.35);
  --warn: #f59e0b;
  --good: #22c55e;

  --shadow: 0 18px 40px rgba(0,0,0,.35);
  --focus: rgba(14,165,233,.35);
  --surface: rgba(255,255,255,.06);
  --surface2: rgba(255,255,255,.03);
  --thead: rgba(255,255,255,.05);
  --hover: rgba(255,255,255,.04);
  --input-bg: var(--surface2);
}

html[data-theme="light"]{
  --bg: #eef3f6;
  --bg2: #f6fbff;
  --card: #ffffff;
  --card2: #f8fafc;
  --text: #0f172a;
  --muted: #4b5563;
  --border: #e2e8f0;
  --topbar-bg: rgba(255,255,255,.85);
  --topbar-border: rgba(15,23,42,.12);
  --nav-text: #334155;
  --nav-active-bg: rgba(2,132,199,.12);
  --nav-active-border: rgba(2,132,199,.28);
  --nav-hover-bg: rgba(15,118,110,.10);
  --nav-hover-border: rgba(15,118,110,.22);
  --accent: #0f766e;
  --accent-2: #0284c7;
  --accent-ink: #e6fffa;
  --danger: #ef4444;
  --surface: #f1f5f9;
  --surface2: #f8fafc;
  --thead: #f3f4f6;
  --hover: #eaf0f7;
  --input-bg: #ffffff;
  --dangerText: #991b1b;
  --dangerBg: rgba(239,68,68,.10);
  --dangerBorder: rgba(239,68,68,.30);
  --shadow: 0 18px 30px rgba(15,23,42,.12);
}

*{ box-sizing:border-box; }
html, body{ height:100%; }
body{
  margin:0;
  font-family: "Source Sans 3", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  position: relative;
}
body::before{
  content:"";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(800px 420px at 12% -8%, rgba(37,194,160,.25), transparent 60%),
    radial-gradient(740px 440px at 88% -12%, rgba(14,165,233,.20), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  z-index: -2;
}
body::after{
  content:"";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 26px 26px;
  opacity: .22;
  z-index: -1;
  pointer-events: none;
}

img{ max-width: 100%; height: auto; display:block; }
a{ color: inherit; text-decoration: none; }
a:hover{ text-decoration: underline; }

h1, h2, h3, .h1, .pageHeader h1{
  font-family: "Space Grotesk", "Segoe UI", Tahoma, sans-serif;
  letter-spacing: -0.02em;
}

/* Topbar */
.topbar{
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--topbar-border);
}
.topbar__inner{
  max-width: 1360px;
  margin: 0 auto;
  padding: 14px 20px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand{
  display:flex;
  align-items:center;
  gap: 10px;
}
.brand img{ height: 28px; }
.nav{
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
}
.nav a{
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--nav-text);
  font-weight: 700;
}
.nav a.active{
  background: var(--nav-active-bg);
  border-color: var(--nav-active-border);
  color: var(--text);
}
.nav a:hover{
  background: var(--nav-hover-bg);
  border-color: var(--nav-hover-border);
  text-decoration: none;
}

/* Layout */
.container{
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 20px 48px;
}
.h1{ font-size: 22px; font-weight: 700; }
.muted{ color: var(--muted); font-size: 13px; }
.mt-8{ margin-top: 8px; }
.mt-12{ margin-top: 12px; }
.mt-16{ margin-top: 16px; }

.row{
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}
.row > *{
  flex: 1 1 160px;
  min-width: 0;
  max-width: 100%;
}
.row.noGrow > *{ flex: 0 0 auto; min-width: 0; }
.actionsRow > *{ flex: 0 0 auto; min-width: 0; }

/* Cards */
.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 14px;
}
@media (max-width: 980px){ .grid{ grid-template-columns: 1fr; } }

/* Buttons */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover{ background: var(--surface); text-decoration: none; }
.btn:disabled{ opacity: .55; cursor:not-allowed; }
.btn.primary{
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #021b1a;
  border-color: rgba(37,194,160,.45);
}
.btn.primary:hover{ filter: brightness(0.98); }
.btn.ghost{ background: transparent; }
.btn.danger{
  background: var(--dangerBg);
  border-color: var(--dangerBorder);
  color: var(--dangerText);
}
.btn.danger:hover{ background: rgba(239,68,68,.18); }
.btn.small{ padding: 8px 10px; font-size: 13px; border-radius: 10px; }

/* Inputs */
label{ display:block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 700; }
input, select, textarea{
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus{
  border-color: rgba(14,165,233,.65);
  box-shadow: 0 0 0 3px rgba(14,165,233,.18);
}
textarea{ min-height: 42px; resize: vertical; }

/* Status */
.pill{
  display:inline-flex;
  align-items:center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  font-size: 12px;
  font-weight: 900;
}
.status{
  display:inline-flex;
  align-items:center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
}
.status.good{ background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.35); color: #bbf7d0; }
.status.warn{ background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.40); color: #fde68a; }
.status.bad{ background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.40); color: #fecaca; }
html[data-theme="light"] .status.good{
  background: rgba(34,197,94,.18);
  border-color: rgba(34,197,94,.40);
  color: #14532d;
}
html[data-theme="light"] .status.warn{
  background: rgba(245,158,11,.20);
  border-color: rgba(245,158,11,.45);
  color: #92400e;
}
html[data-theme="light"] .status.bad{
  background: rgba(239,68,68,.18);
  border-color: rgba(239,68,68,.45);
  color: #7f1d1d;
}

/* Alerts */
.alerts{ display:grid; gap: 10px; margin-bottom: 12px; }
.alert{
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  background: var(--card2);
  font-size: 13px;
}
.alert.ok{ border-color: rgba(34,197,94,.35); background: rgba(34,197,94,.08); }
.alert.warn{ border-color: rgba(245,158,11,.40); background: rgba(245,158,11,.10); }
.alert.error{ border-color: rgba(239,68,68,.40); background: rgba(239,68,68,.10); }

/* Tables */
.tableWrap{
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: auto;
  background: var(--card2);
}
table{
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 720px;
}
th, td{
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
th{
  background: var(--thead);
  color: var(--muted);
  font-weight: 800;
}
tr:hover td{ background: var(--card2); }

.right{ text-align: right !important; }
.center{ text-align: center !important; }
.num{ font-variant-numeric: tabular-nums; }

/* Entry cards */
.entry{
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--card2);
  min-width: 0;
}
.entry.handled{ background: var(--input-bg); }
.entryGrid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 10px;
}
@media (max-width: 980px){ .entryGrid{ grid-template-columns: 1fr; } }
.entryActions{
  margin-top: 10px;
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Footer */
.footer{
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 20px 30px;
  display:flex;
  gap: 12px;
  align-items:center;
  justify-content:center;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.footer a{ color: var(--muted); }

/* Table form controls */
.tableWrap input, .tableWrap select{
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.tableWrap td{ white-space: normal; }
.tableWrap td input{ white-space: nowrap; }

/* Fix action buttons in cells */
.tableWrap td.actionsCell, .tableWrap th.actionsCell{
  white-space: normal !important;
}
.tableWrap td.actionsCell{
  overflow: visible;
  min-width: 220px;
}
.actionsStack{
  display:flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  justify-content: flex-start;
}
.actionsStack .btn{
  width: 100%;
  white-space: normal;
  line-height: 1.15;
  padding: 10px 12px;
}

::placeholder{ color: rgba(156,163,175,.75); }
html[data-theme="dark"]{ color-scheme: dark; }
html[data-theme="light"]{ color-scheme: light; }

select, input, textarea{
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
select option{
  background: var(--card);
  color: var(--text);
}

.chartWrap{ background: var(--card) !important; }

.userbox{
  display:flex;
  align-items:center;
  gap:10px;
  margin-left:auto;
}
.userbox__name{
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  opacity: .9;
}
.authWrap{
  min-height: calc(100vh - 160px);
  display:flex;
  align-items:center;
  justify-content:center;
}
.authCard{
  width: min(520px, 92vw);
}

.pageHeader{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:16px;
  flex-wrap:wrap;
  margin-bottom:16px;
}
.headerActions{
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: nowrap;
}
.headerActions .btn{
  white-space: nowrap;
  text-align: center;
  min-width: 150px;
}
@media (max-width: 720px){
  .headerActions{
    flex-wrap: wrap;
    width: 100%;
  }
}
.pageHeader h1{
  margin:0;
  font-size:26px;
  letter-spacing:-0.02em;
}
.pageHeader h2{ margin:0; }

.grid2{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:16px;
}
@media (max-width: 900px){
  .grid2{ grid-template-columns: 1fr; }
}

.actionsRow{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  justify-content:flex-end;
  align-items:center;
}
.actionsColumn{
  flex-direction: column;
  align-items: stretch;
}
.actionsInline{
  flex-wrap: wrap;
  justify-content: flex-start;
  row-gap: 6px;
}
.actionsInline > *{
  flex: 0 0 auto;
}
.actionsInline .btn{
  white-space: normal;
  line-height: 1.2;
  padding: 9px 12px;
}
.actionsFull td{
  padding-top: 8px;
  padding-bottom: 12px;
}
.actionsColumn .checkRow{
  width: 100%;
}
.actionsColumn .btn{
  width: 100%;
  white-space: normal;
  line-height: 1.2;
  text-align: center;
}
.actionsColumn .checkRow{
  justify-content: flex-start;
}
.bulkBtn{
  padding: 12px 16px;
  font-size: 14px;
  white-space: normal;
}

.detailsBlock{
  display:flex;
  flex-direction:column;
  width:100%;
}
.detailsBlock > summary{
  list-style:none;
  align-self:flex-end;
}
.detailsBlock > summary::-webkit-details-marker{ display:none; }
.detailsBlock > .card.inset{
  width:100%;
  max-width:100%;
}
.detailsInline summary{
  list-style:none;
}
.detailsInline summary::-webkit-details-marker{ display:none; }

.card.inset{
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 12px;
}

.gridForm{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:12px;
}
.grid1{ grid-template-columns: 1fr !important; }

.gridForm label{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:13px;
  color: var(--muted);
}
.gridForm input, .gridForm select, .gridForm textarea{
  font-size:14px;
  color: var(--text);
}

.checkRow{
  display:flex;
  align-items:center;
  gap:8px;
  user-select:none;
}
.checkRow input[type="checkbox"]{
  width:16px;
  height:16px;
}

.pillRow{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}

.legend{
  display:flex;
  flex-wrap:wrap;
  gap:10px 14px;
  color: var(--muted);
  font-size:13px;
}
.legendItem{
  display:flex;
  align-items:center;
  gap:8px;
}
.swatch{
  width:12px;
  height:12px;
  border-radius:3px;
  border: 1px solid var(--border);
}

.fieldRow{
  display:grid;
  grid-template-columns: 180px 1fr auto;
  gap:10px;
  align-items:start;
  padding:10px 0;
  border-top: 1px solid var(--border);
}
.fieldRow:first-of-type{ border-top:none; }
.fieldLabel{
  color: var(--muted);
  font-size:13px;
}
.fieldValue input, .fieldValue textarea{ width:100%; }
.fieldActions{
  display:flex;
  justify-content:flex-end;
}

.bulkPick{
  justify-content:flex-end;
  color: var(--muted);
  font-size:12px;
}
.bulkPick span{ opacity:.9; }

.hr{height:1px;background:var(--border);margin:12px 0;opacity:.6;}

.totalsRow td{
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

.inlineInput{
  width:100%;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.inlineInput:focus{
  border-color: rgba(37,194,160,.6);
  box-shadow: 0 0 0 3px rgba(37,194,160,.18);
}

@keyframes riseIn{
  from{ opacity:0; transform: translateY(8px); }
  to{ opacity:1; transform: translateY(0); }
}
main > *{ animation: riseIn 420ms ease both; }
main > *:nth-child(2){ animation-delay: 40ms; }
main > *:nth-child(3){ animation-delay: 80ms; }
main > *:nth-child(4){ animation-delay: 120ms; }

@media (prefers-reduced-motion: reduce){
  *{ animation: none !important; transition: none !important; }
}

@media (max-width: 720px){
  .container{ padding: 18px 16px 40px; }
  table{ min-width: 640px; }
  .fieldRow{ grid-template-columns: 1fr; }
}
