@font-face {
  font-family: "Golos Text";
  src: url("/fonts/golos-text.ttf") format("truetype");
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --surface: #fff;
  --panel: #f4f4f4;
  --inset: #eceff1;
  --hover: #dde5e9;
  --text: #292c2f;
  --muted: #52575c;
  --border: #d7dadd;
  --control-border: #969da2;
  --band: #1b1b1b;
  --on-band: #f7f7f7;
  --accent: #276d72;
  --accent-hover: #20585c;
  --accent-soft: #e6f0ef;
  --danger: #84453e;
  --danger-soft: #f4e7e5;
  --shadow-control: 0 1px 2px rgb(35 43 48 / 14%), 0 2px 5px rgb(35 43 48 / 8%);
  --shadow-panel: 0 3px 8px rgb(35 43 48 / 8%), 0 16px 36px rgb(35 43 48 / 10%);
  --page-width: 1296px;
  --gutter: clamp(16px, 4vw, 40px);
  --panel-overlap: 36px;
  font-family: "Golos Text", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; }

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 4px rgb(35 43 48 / 9%), 0 10px 24px rgb(35 43 48 / 9%);
}

.topbar-inner, .page-title, .sheet {
  width: min(calc(100% - 2 * var(--gutter)), var(--page-width));
  margin-inline: auto;
}

.topbar-inner {
  min-height: 75px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 28px;
}

.brand {
  color: var(--muted);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.3px;
  text-decoration: none;
  white-space: nowrap;
}
.brand strong { color: var(--accent); font-weight: 700; }

.sections { display: flex; gap: 3px; align-items: center; }
.sections a {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  padding: 0 14px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.sections a:hover { background: var(--hover); color: var(--text); }
.sections a[aria-current="page"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-control); }

.user-profile { position: relative; width: 256px; max-width: 100%; margin-left: auto; }
.profile-trigger {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  list-style: none;
  cursor: pointer;
}
.profile-trigger::-webkit-details-marker { display: none; }
.profile-trigger:hover { background: var(--hover); }
.user-profile details[open] .profile-trigger {
  border-color: var(--border);
  border-bottom-color: transparent;
  border-radius: 8px 8px 0 0;
  background: var(--surface);
}
.profile-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 600;
}
.profile-label, .profile-summary { display: grid; gap: 3px; min-width: 0; }
.profile-label :is(strong, small) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-profile strong { font-size: 13px; font-weight: 600; }
.user-profile small { color: var(--muted); font-size: 12px; }
.profile-chevron {
  justify-self: center;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border: solid var(--muted);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.user-profile details[open] .profile-chevron { margin-top: 4px; transform: rotate(225deg); }
.profile-dropdown {
  position: absolute;
  top: calc(100% - 1px);
  right: 0;
  width: 100%;
  padding: 7px;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  box-shadow: 0 14px 26px rgb(35 43 48 / 14%);
}
.profile-summary { padding: 8px 9px 10px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.profile-logout { width: 100%; min-height: 38px; margin-top: 4px; padding: 0 9px; border: 0; text-align: left; }
.profile-error { margin: 6px 9px; color: var(--danger); font-size: 13px; }

.page-band {
  padding: 28px 0 calc(var(--panel-overlap) + 24px);
  color: var(--on-band);
  background: var(--band);
}

main { padding-bottom: 24px; }
.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 44px;
}

h1 { margin: 0; font-size: 33px; line-height: 1.2; font-weight: 550; letter-spacing: -1px; }

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  margin-top: calc(-1 * var(--panel-overlap));
  padding: clamp(14px, 2vw, 24px);
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow-panel);
}

.login-panel p { margin: 0; }
.toolbar, .footer {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.toolbar { padding-bottom: 16px; }
.footer { align-items: center; justify-content: space-between; padding-top: 12px; }
.footer:has(.status:empty):not(:has(:is(#pagination, #journal-pagination):not([hidden]))) { display: none; }
.actions, #pagination { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions { margin-left: auto; }
.search { width: min(268px, 100%); }
.city-picker { min-width: 155px; }

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

button, select, input {
  font: inherit;
  font-size: 14px;
  min-width: 0;
  min-height: 40px;
  padding: 6px 12px;
  color: var(--text);
  background-color: transparent;
  border: 1px solid var(--control-border);
  border-radius: 7px;
}

select {
  appearance: none;
  padding-right: 32px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

button { padding-inline: 14px; border-radius: 6px; font-weight: 500; cursor: pointer; }
:is(button, select, input):enabled:hover { background-color: var(--hover); }
:is(select, input):focus { border-color: var(--accent); background-color: var(--surface); }
button:disabled, input:disabled, select:disabled { opacity: .55; cursor: default; }

.primary {
  min-width: 124px;
  color: var(--surface);
  background-color: var(--accent);
  border-color: var(--accent);
}

.primary:enabled:hover { background-color: var(--accent-hover); border-color: var(--accent-hover); }
.page-band .primary:disabled { opacity: 1; background: #303638; border-color: #626a6d; color: #c9c9c9; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.page-band :focus-visible { outline-color: var(--on-band); }

.grid {
  min-height: 240px;
  max-height: max(240px, calc(100dvh - 310px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}

table { border-spacing: 0; width: 100%; }

th, td {
  padding: 0;
  border-bottom: 1px solid var(--border);
}
#table :is(th, td):not(:last-child) { border-right: 1px solid var(--border); }

thead th {
  padding: 10px;
  position: sticky;
  z-index: 2;
  top: 0;
  color: var(--muted);
  background: var(--inset);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

th[scope="row"] {
  padding: 0 10px;
  color: var(--muted);
  text-align: right;
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

tbody tr:nth-child(even) { background: #f8f8f8; }
tbody tr:focus-within { background: var(--accent-soft); }
#table td:not(:last-child) { min-width: 104px; }
#table td:nth-child(2) { min-width: 155px; }
#table td:nth-child(3) { min-width: 220px; width: 28%; }
#table td:last-child { padding: 3px 8px; width: 1%; }

#masks-table th, #masks-table td { padding: 8px 16px; }
#masks-table th { height: 44px; }
#masks-table td:first-child { overflow-wrap: anywhere; }
#masks-table td:nth-child(2) { width: 120px; white-space: nowrap; color: var(--muted); }
#masks-table td:last-child { width: 1%; }
#masks-table button { min-height: 32px; }

.journal-filters > label { flex: 1 1 130px; min-width: 0; }
.journal-filters > label:has(input[type="datetime-local"]) { flex-basis: 185px; }
.journal-filters :is(select, input) { width: 100%; }
.journal-filter-reset {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  margin-left: auto;
  padding: 0;
}
.journal-grid { min-height: 240px; }
#journal-table th, #journal-table td { padding: 10px 12px; vertical-align: top; }
#journal-table th { height: 44px; }
#journal-table td:first-child { min-width: 150px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#journal-table td:nth-child(2), #journal-table td:nth-child(3) { min-width: 120px; }
#journal-table td:nth-child(4) { min-width: 160px; overflow-wrap: anywhere; }
#journal-table td:last-child { min-width: 270px; }
.journal-change { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.journal-change p { margin: 0; }
.journal-change button { min-height: 32px; padding: 4px 9px; }
.journal-dialog[open] { display: flex; flex-direction: column; width: min(720px, calc(100vw - 24px)); }
.journal-dialog-header { flex: none; }
.journal-dialog-header p { margin: 4px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.journal-dialog-body { min-height: 0; overflow: auto; padding: 14px 20px 18px; overflow-wrap: anywhere; }
.journal-detail-content p { margin: 4px 0; }
.journal-detail-content ul { display: grid; gap: 5px; margin: 5px 0; padding-left: 20px; }
.journal-detail-content ul ul { gap: 2px; color: var(--muted); }
.journal-detail-content li { white-space: pre-wrap; }
#journal-detail-retry { min-height: 32px; margin-top: 8px; }
#journal-pagination { display: flex; gap: 8px; align-items: center; color: var(--muted); }
#journal-pagination button { min-height: 34px; }

.view-toggle {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
}
.view-toggle button { min-height: 32px; padding: 0 10px; border: 0; border-radius: 5px; font-size: 13px; }
.view-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-control); }

.mask-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(235px, 100%), 1fr));
  align-items: start;
  gap: 16px;
  padding: 16px;
}
.mask-card { min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.mask-thumbnail {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: 100%;
  height: 204px;
  padding: 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--muted);
  background: var(--inset);
}
.mask-thumbnail:enabled:hover { background: var(--accent-soft); }
.mask-thumbnail:focus-visible { outline-offset: -3px; }
.mask-thumbnail canvas, .pdf-stage canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: var(--surface);
  box-shadow: var(--shadow-control);
}
.mask-card-footer { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 10px; }
.mask-caption { display: grid; gap: 3px; min-width: 0; }
.mask-caption strong { overflow-wrap: anywhere; font-size: 14px; }
.mask-caption span { color: var(--muted); font-size: 13px; }
.mask-card-footer button { min-height: 32px; padding: 5px 8px; }

.pdf-preview, .journal-dialog {
  width: min(960px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: inherit;
  box-shadow: 0 22px 60px rgb(20 23 25 / 28%);
}
.pdf-preview::backdrop, .journal-dialog::backdrop { background: rgb(27 27 27 / 58%); }
.pdf-toolbar, .journal-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}
.pdf-toolbar h2, .journal-dialog-header h2 { margin: 0; font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.pdf-stage {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  height: min(68dvh, 720px);
  padding: 16px;
  background: var(--inset);
}
.pdf-stage p { margin: 0; color: var(--muted); }
.pdf-pages { display: flex; gap: 12px; justify-content: center; align-items: center; padding: 12px; }

textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 36px;
  resize: none;
  padding: 8px 10px;
  border: 0;
  font: inherit;
  font-size: 14px;
  color: inherit;
  background: transparent;
  line-height: 20px;
  white-space: pre;
}

textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface); }

.remove { color: var(--danger); min-height: 30px; padding: 3px 7px; border-color: transparent; }
.remove:enabled:hover { background: var(--danger-soft); }
.empty { margin: 26px 16px; color: var(--muted); }
.status { margin: 0; color: var(--muted); }
.status.error { color: var(--danger); }
.status a { color: var(--accent); white-space: nowrap; }
#pagination { color: var(--muted); margin-left: auto; }
#pagination button { min-height: 34px; }

@media (min-width: 1024px) and (min-height: 640px) {
  .workspace-page { display: flex; flex-direction: column; height: 100dvh; }
  .workspace-page main { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .workspace-page :is(.topbar, .page-band, .toolbar, .footer) { flex-shrink: 0; }
  .workspace-page .sheet { flex: 1; min-height: 0; }
  .workspace-page .grid { flex: 1; min-height: 0; max-height: none; }
}

@media (min-width: 1024px) {
  #table thead th:nth-child(2), #table tbody td:nth-child(2) {
    position: sticky;
    left: 0;
    box-shadow: 5px 0 9px -7px #292c2f80;
  }

  #table thead th:last-child, #table tbody td:last-child {
    position: sticky;
    right: 0;
    box-shadow: -5px 0 9px -7px #292c2f80;
  }

  #table thead :is(th:nth-child(2), th:last-child) { z-index: 3; }
  #table tbody :is(td:nth-child(2), td:last-child) { z-index: 1; background: var(--surface); }
  #table tbody tr:nth-child(even) :is(td:nth-child(2), td:last-child) { background: #f8f8f8; }
  #table tbody tr:focus-within :is(td:nth-child(2), td:last-child) { background: var(--accent-soft); }
}

@media (max-width: 620px) {
  .topbar-inner { min-height: 64px; padding-block: 8px; gap: 4px 12px; }
  .sections a { min-height: 36px; padding-inline: 9px; }
  .user-profile { width: 48px; }
  .profile-trigger { grid-template-columns: 36px; min-height: 44px; padding: 3px 5px; }
  .profile-label, .profile-chevron { display: none; }
  .profile-dropdown { width: 220px; border-top: 1px solid var(--border); border-radius: 8px; }
  .page-band { padding-top: 22px; }
  h1 { font-size: 29px; }
  .actions { margin-left: 0; }
  .grid { max-height: max(260px, calc(100dvh - 350px)); }
}

@media (max-width: 410px) {
  .topbar-inner .sections { order: 1; flex-basis: 100%; }
}
