:root {
  color-scheme: dark;
  --bg: #09111f;
  --panel: #101b2d;
  --panel-2: #152238;
  --line: #27364d;
  --text: #e8eef8;
  --muted: #91a3bc;
  --blue: #4f8cff;
  --blue-soft: rgba(79, 140, 255, .14);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 760px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

.topbar {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(110deg, #0d1728, #111f35);
}

h1 { margin: 0; font-size: 23px; letter-spacing: -.5px; }
h1 span { color: var(--blue); }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

.button, select, input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1929;
  color: var(--text);
  font: inherit;
}

.button { padding: 9px 14px; cursor: pointer; }
.button:hover { border-color: var(--blue); }
.button:disabled { cursor: wait; opacity: .6; }
.button-primary { border-color: #2563eb; background: #2563eb; color: white; }
.button-primary:hover { background: #1d4ed8; }
.button-success { border-color: #15803d; background: #15803d; color: white; }
.button-success:hover { background: #166534; }

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}

.sidebar-heading {
  display: flex;
  justify-content: space-between;
  padding: 4px 10px 12px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1.2px;
}

.sidebar-heading strong {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: #a9c5ff;
  text-align: center;
}

.file-list { display: grid; gap: 5px; }

.file-item {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.file-item:hover { background: rgba(255,255,255,.035); }
.file-item.active { border-color: rgba(79,140,255,.35); background: var(--blue-soft); }

.file-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #107c41;
  color: white;
  font-weight: 800;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.file-size { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.workspace { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr; }

.controls {
  display: flex;
  gap: 14px;
  align-items: end;
  padding: 12px 15px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
select, input { height: 36px; padding: 0 10px; outline: none; }
select:focus, input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.search { flex: 1; }

.markup-control {
  display: flex;
  position: relative;
  align-items: end;
  gap: 8px;
  padding: 0 0 16px 14px;
  border-left: 1px solid var(--line);
}

.markup-input {
  height: 36px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1929;
}

.markup-input:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.markup-input input {
  width: 64px;
  border: 0;
  background: transparent;
  text-align: right;
}
.markup-input input:focus { box-shadow: none; }
.markup-input span { padding-right: 10px; color: var(--muted); }
.markup-actions { display: flex; gap: 6px; }
.markup-targets {
  position: absolute;
  bottom: -1px;
  left: 14px;
  right: 0;
  overflow: hidden;
  color: #8fb6ff;
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.markup-control.unavailable { opacity: .45; }
.markup-control.unavailable .button-primary { cursor: not-allowed; }

body.presentation .markup-control,
body.presentation #refreshButton {
  display: none;
}

body.presentation footer {
  visibility: hidden;
}

.empty-state {
  align-self: center;
  justify-self: center;
  color: var(--muted);
  text-align: center;
}

.empty-icon { color: #3e5680; font-size: 54px; }
.empty-state h2 { margin: 10px 0 4px; color: #cbd8eb; font-size: 18px; }
.empty-state p { margin: 0; font-size: 13px; }

.table-panel { min-height: 0; overflow: auto; background: #f8fafc; color: #162033; }
.hidden { display: none !important; }

table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
  font-size: 12px;
  white-space: nowrap;
}

th, td {
  height: 29px;
  max-width: 360px;
  padding: 5px 9px;
  overflow: hidden;
  border-right: 1px solid #dce3ec;
  border-bottom: 1px solid #dce3ec;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e6ebf2;
  color: #334155;
  font-weight: 700;
  text-align: left;
}

.column-title {
  display: block;
  max-width: 290px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 10px;
  background: #cbd5e1;
  color: #475569;
  font-size: 9px;
  font-weight: 600;
}

.type-badge b { font-size: 9px; }
th.type-number .type-badge { background: #dbeafe; color: #1d4ed8; }
th.type-currency .type-badge { background: #dcfce7; color: #15803d; }
th.type-percentage .type-badge { background: #fef3c7; color: #b45309; }
th.type-date .type-badge { background: #ede9fe; color: #6d28d9; }
th.type-boolean .type-badge { background: #cffafe; color: #0e7490; }

td.type-number,
td.type-currency,
td.type-percentage {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

td.type-currency {
  color: #08783e;
  font-weight: 600;
}

td.type-percentage { color: #a35709; }
td.type-date { color: #6437a2; }
td.type-boolean { color: #08738a; font-weight: 700; text-align: center; }
td.type-error { background: #fee2e2 !important; color: #b91c1c; font-weight: 700; }
td.type-formula { color: #1d4ed8; }

th:first-child, td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 58px;
  min-width: 58px;
  background: #eef2f7;
  color: #64748b;
  text-align: right;
}

th:first-child { z-index: 3; background: #dce3ec; }
tbody tr:nth-child(even) td:not(:first-child) { background: #f1f5f9; }
tbody tr:hover td { background: #dbeafe !important; }

footer {
  height: 34px;
  padding: 8px 15px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: #0c1524;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Logowanie */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 25% 20%, rgba(79, 140, 255, .18), transparent 34%),
    linear-gradient(135deg, #07101d, #101d32);
}

body.locked .login-screen { display: grid; }
body.locked .topbar,
body.locked .layout,
body.locked footer {
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: min(100%, 390px);
  display: grid;
  gap: 18px;
  padding: 34px;
  border: 1px solid rgba(148, 163, 184, .2);
  border-radius: 18px;
  background: rgba(16, 27, 45, .96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .42);
}

.login-card h1 { font-size: 30px; }
.login-sub { margin: -8px 0 2px; color: var(--muted); font-size: 13px; }
.login-card label { font-size: 12px; }
.login-card input { width: 100%; }
.login-card .button { min-height: 42px; margin-top: 2px; }
.login-error { min-height: 18px; margin: -7px 0 0; color: #fca5a5; font-size: 12px; }

/* Pasek użytkownika i lista plików */
.top-actions {
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  max-width: 180px;
  overflow: hidden;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .035);
  color: #cbd8eb;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item {
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 2px;
  padding: 3px;
  cursor: default;
}

.file-open {
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.file-meta { min-width: 0; }
.file-name { display: block; }

.file-menu {
  width: 30px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.file-open:hover,
.file-menu:hover { background: rgba(255, 255, 255, .06); }
.file-menu:hover { color: var(--text); }

.badge {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .2px;
  text-transform: uppercase;
  vertical-align: 1px;
}

.badge-sold { background: rgba(239, 68, 68, .18); color: #fca5a5; }
.badge-reserved { background: rgba(245, 158, 11, .18); color: #fcd34d; }
.file-item.status-sold { border-color: rgba(239, 68, 68, .28); }
.file-item.status-reserved { border-color: rgba(245, 158, 11, .28); }

/* Oznaczenia wierszy */
.row-num { cursor: pointer; user-select: none; }
.row-no { vertical-align: middle; }
.row-mark-hint {
  margin-left: 6px;
  color: #94a3b8;
  font-size: 9px;
  opacity: 0;
}

tr:hover .row-mark-hint { opacity: 1; }

.row-flag {
  display: inline-grid;
  width: 17px;
  height: 17px;
  place-items: center;
  margin-left: 6px;
  border-radius: 50%;
  color: white;
  font-size: 9px;
  font-weight: 800;
}

.row-sold .row-flag { background: #dc2626; }
.row-reserved .row-flag { background: #d97706; }
.row-sold td { background: #fee2e2 !important; color: #7f1d1d; }
.row-reserved td { background: #fef3c7 !important; color: #78350f; }
.row-sold:hover td { background: #fecaca !important; }
.row-reserved:hover td { background: #fde68a !important; }

/* Menu kontekstowe */
.mark-menu {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  display: grid;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111d30;
  box-shadow: 0 16px 45px rgba(0, 0, 0, .4);
}

.menu-item {
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover { background: rgba(79, 140, 255, .14); }
.menu-item.active { background: #2563eb; color: white; }
.menu-item.danger { color: #fca5a5; }

/* Modal historii */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(3, 8, 17, .72);
  backdrop-filter: blur(5px);
}

.modal-card {
  width: min(100%, 980px);
  max-height: min(82vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { overflow: auto; padding: 18px; }
.modal-body h3 { margin: 24px 0 9px; color: #d9e4f3; font-size: 13px; }
.modal-body h3:first-of-type { margin-top: 14px; }
.muted { color: var(--muted); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

.hist-table {
  width: 100%;
  min-width: 640px;
  color: var(--text);
  white-space: normal;
}

.hist-table th,
.hist-table td {
  position: static;
  width: auto;
  min-width: 0;
  height: auto;
  padding: 9px 10px;
  border-color: var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}

.hist-table th {
  background: #17253a;
  color: #aebed3;
  font-size: 10px;
  letter-spacing: .35px;
  text-transform: uppercase;
}

.hist-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, .025); }
.hist-table tbody tr:hover td { background: rgba(79, 140, 255, .09) !important; }

@media (max-width: 1180px) {
  .topbar { height: auto; min-height: 78px; padding-block: 12px; }
  .layout { grid-template-columns: 270px minmax(0, 1fr); }
  .controls { flex-wrap: wrap; }
  .search { min-width: 260px; }
  .markup-control {
    width: 100%;
    padding-left: 0;
    border-left: 0;
  }
  .markup-targets { left: 0; }
}
