:root {
  --bg: #eeeeec;
  --surface: #ffffff;
  --surface-soft: #f5f5f3;
  --ink: #111111;
  --muted: #696969;
  --line: #d7d7d2;
  --accent: #111111;
  --accent-dark: #000000;
  --danger: #9f1d1d;
  --warning: #806000;
  --radius: 8px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

.login-page {
  min-height: 100vh;
  background: #090909;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid #2d2d2d;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
  padding: 26px;
}

.login-brand {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.login-brand strong,
.login-brand span {
  display: block;
}

.login-brand strong {
  font-size: 28px;
  line-height: 1.1;
}

.login-brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form button {
  width: 100%;
}

.login-error {
  border: 1px solid #111111;
  border-radius: var(--radius);
  padding: 10px 12px;
  color: #111111;
  background: #f3f3f0;
  font-weight: 700;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 78px minmax(0, 1fr);
}

.mobile-menu-button,
.mobile-menu-backdrop {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: #090909;
  color: #ffffff;
  padding: 24px 18px;
  border-right: 1px solid #000000;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #9b9b9b;
  font-size: 12px;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  margin: 0 0 16px;
  border: 1px solid #303030;
  border-radius: var(--radius);
  color: #e8e8e8;
  background: #151515;
  font-weight: 700;
}

.sidebar-toggle:hover {
  color: #000000;
  background: #ffffff;
  border-color: #ffffff;
}

.sidebar-toggle-icon {
  display: inline-block;
  font-size: 20px;
  line-height: 1;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.sidebar-logout {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: #cfcfcf;
  background: transparent;
  padding: 13px 14px;
  text-align: left;
  white-space: nowrap;
}

.sidebar-logout {
  margin-top: auto;
  border-color: #303030;
  color: #ffffff;
  background: #151515;
  font-weight: 700;
}

.nav-item::before,
.sidebar-logout::before {
  content: attr(data-short);
  display: none;
}

.nav-item:hover,
.nav-item.active,
.sidebar-logout:hover {
  color: #000000;
  background: #ffffff;
  border-color: #ffffff;
}

.sidebar-collapsed .sidebar {
  padding: 20px 10px;
}

.sidebar-collapsed .brand {
  justify-content: center;
  margin-bottom: 16px;
}

.sidebar-collapsed .sidebar-toggle-text,
.sidebar-collapsed .nav-label {
  display: none;
}

.sidebar-collapsed .brand-text {
  display: block;
  text-align: center;
}

.sidebar-collapsed .brand strong {
  font-size: 12px;
  line-height: 1.1;
}

.sidebar-collapsed .brand span {
  display: none;
}

.sidebar-collapsed .sidebar-toggle {
  min-height: 38px;
  padding: 0;
}

.sidebar-collapsed .sidebar-toggle-icon {
  transform: rotate(180deg);
}

.sidebar-collapsed .nav-item,
.sidebar-collapsed .sidebar-logout {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 0;
  text-align: center;
}

.sidebar-collapsed .nav-item::before,
.sidebar-collapsed .sidebar-logout::before {
  display: block;
  font-weight: 800;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid #cfcfca;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.15;
  font-weight: 800;
}

h2 {
  font-size: 18px;
  font-weight: 800;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #111111;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.11);
}

.topbar input {
  width: min(280px, 100%);
}

.primary,
.secondary {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 14px;
  min-height: 42px;
  white-space: nowrap;
  font-weight: 700;
}

.primary {
  color: #fff;
  background: #111111;
  border-color: #111111;
}

.primary.dark {
  background: #000000;
  border-color: #000000;
}

.primary:hover,
.primary.dark:hover {
  background: #2a2a2a;
  border-color: #2a2a2a;
}

.secondary {
  color: var(--ink);
  background: #ffffff;
  border-color: #b9b9b3;
}

.secondary:hover {
  background: #111111;
  border-color: #111111;
  color: #ffffff;
}

.danger {
  border: 1px solid #2f2f2f;
  border-radius: var(--radius);
  color: #ffffff;
  background: #2b2b2b;
  min-height: 42px;
  padding: 10px 14px;
  white-space: nowrap;
  font-weight: 700;
}

.danger:hover {
  background: #000000;
  border-color: #000000;
}

.small {
  min-height: 34px;
  padding: 7px 10px;
}

.alert {
  margin-bottom: 16px;
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #ffffff;
  color: #111111;
  border: 1px solid #111111;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
  min-height: 98px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
}

.owner-stats {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-top: 16px;
}

.statistics-grid {
  margin-top: 16px;
}

.content-grid,
.split-layout,
.orders-layout,
.masters-layout {
  display: grid;
  gap: 16px;
}

.content-grid {
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr);
}

.split-layout,
.orders-layout {
  grid-template-columns: minmax(0, 1fr) 390px;
}

.records-layout,
.masters-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

.panel {
  min-width: 0;
  overflow: hidden;
  outline: 1px solid rgba(255, 255, 255, 0.72);
}

.panel:hover {
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.1);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.filters-row {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #f4f4f1;
}

.filters-row label {
  width: 190px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #4b4b4b;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  background: #fafaf8;
}

tbody tr:hover {
  background: #f7f7f4;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: #f7f7f4;
}

.row-hint {
  color: var(--muted);
  text-align: right;
}

.clickable:hover .row-hint {
  color: var(--text);
}

.num {
  text-align: right;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #111111;
  color: #ffffff;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-select {
  min-width: 170px;
  padding: 7px 9px;
  background: #ffffff;
}

.payment-select {
  min-width: 132px;
  padding: 7px 9px;
  border-width: 1px;
  border-radius: var(--radius);
  font-weight: 800;
}

.payment-paid {
  border-color: #1f7a3a;
  color: #0d5f29;
  background: #e8f6ec;
}

.payment-unpaid {
  border-color: #a92323;
  color: #8c1616;
  background: #fdecec;
}

.prepayment-input {
  width: 112px;
  min-height: 34px;
  padding: 6px 8px;
  text-align: right;
}

.salary-advance-input {
  width: 112px;
  min-height: 34px;
  padding: 6px 8px;
  text-align: right;
}

.record-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.record-list,
.status-list,
.catalog-grid {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.record,
.status-row,
.catalog-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
}

.record {
  display: grid;
  gap: 4px;
}

.record strong {
  font-size: 15px;
}

.record span,
.record small,
.empty {
  color: var(--muted);
}

.record-list.compact .record {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.form-panel {
  align-self: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: #555555;
  font-size: 13px;
  font-weight: 700;
}

label.wide,
.wide {
  grid-column: 1 / -1;
}

textarea {
  resize: vertical;
}

.details-panel {
  margin-top: 16px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.detail-item {
  display: grid;
  gap: 5px;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
}

.detail-item strong {
  font-size: 16px;
}

.inline-forms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
}

.catalog-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.catalog-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.catalog-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.dialog-box {
  min-width: 300px;
  padding: 18px;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.services-dialog {
  padding: 0;
}

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

.dialog-head p {
  margin-top: 6px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.service-form {
  border-top: 1px solid var(--line);
}

.record-dialog .form-grid {
  padding-top: 16px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 16px;
}

.photo-card {
  display: grid;
  gap: 8px;
}

.photo-preview {
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  text-align: left;
}

.photo-preview img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f5f5;
}

.photo-preview span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.full-photo-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 54px 18px 18px;
  background: rgba(0, 0, 0, 0.94);
}

.full-photo-overlay[hidden] {
  display: none;
}

.full-photo-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.full-photo-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 81;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: #ffffff;
  color: #000000;
  cursor: pointer;
  font-weight: 700;
}

@media (max-width: 980px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(300px, 78vw);
    height: 100vh;
    padding: 24px 18px;
    border-right: 1px solid #000000;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    box-shadow: 18px 0 48px rgba(0, 0, 0, 0.32);
  }

  .mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  .mobile-menu-button {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 30;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    min-height: 0;
    border: 1px solid #000000;
    border-radius: 50%;
    color: #ffffff;
    background: #090909;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
    padding: 0;
  }

  .mobile-menu-button span {
    display: block;
    width: 21px;
    height: 2px;
    grid-area: 1 / 1;
    border-radius: 999px;
    background: currentColor;
    transition: transform 0.18s ease, opacity 0.18s ease;
  }

  .mobile-menu-button span:nth-child(1) {
    transform: translateY(-7px);
  }

  .mobile-menu-button span:nth-child(3) {
    transform: translateY(7px);
  }

  .mobile-menu-open .mobile-menu-button {
    color: #090909;
    background: #ffffff;
  }

  .mobile-menu-open .mobile-menu-button span:nth-child(1) {
    transform: rotate(45deg);
  }

  .mobile-menu-open .mobile-menu-button span:nth-child(2) {
    opacity: 0;
  }

  .mobile-menu-open .mobile-menu-button span:nth-child(3) {
    transform: rotate(-45deg);
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    border: 0;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.45);
  }

  .mobile-menu-open .mobile-menu-backdrop {
    display: block;
  }

  .brand {
    margin-bottom: 28px;
  }

  .sidebar-toggle {
    display: none;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .nav-item {
    text-align: left;
  }

  .topbar,
  .content-grid,
  .split-layout,
  .orders-layout,
  .masters-layout,
  .inline-forms {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 160px;
  }

  .filters-row {
    align-items: stretch;
    flex-direction: column;
  }

  .filters-row label {
    width: 100%;
  }

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

@media (max-width: 620px) {
  .sidebar {
    width: min(280px, 82vw);
    padding: 18px 14px;
  }

  .mobile-menu-button {
    top: 12px;
    right: 12px;
    width: 46px;
    height: 46px;
  }

  .mobile-menu-button span {
    width: 20px;
  }

  .brand {
    justify-content: flex-start;
  }

  .brand-text {
    text-align: left;
  }

  .brand strong {
    font-size: 18px;
    line-height: 1.1;
  }

  .brand span {
    display: block;
  }

  .sidebar-toggle {
    display: none;
  }

  .nav-label {
    display: inline;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .nav-item,
  .sidebar-logout {
    display: block;
    min-height: 44px;
    padding: 13px 14px;
    text-align: left;
  }

  .nav-item::before,
  .sidebar-logout::before {
    display: none;
  }

  .main {
    padding: 14px;
  }

  .metrics-grid,
  .form-grid,
  .catalog-grid,
  .details-grid {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 10px;
  }
}

@media (max-width: 760px) {
  body {
    background: #f3f3f0;
    font-size: 14px;
  }

  button:hover {
    transform: none;
  }

  .sidebar {
    border-right: 1px solid #000000;
    border-bottom: 0;
  }

  .brand {
    margin-bottom: 12px;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    gap: 14px;
    margin-bottom: 14px;
    padding-bottom: 14px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 16px;
  }

  .topbar p {
    font-size: 13px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .topbar input,
  .topbar-actions > * {
    width: 100%;
  }

  .panel {
    border-radius: 8px;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .filters-row {
    padding: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  input,
  select,
  textarea,
  .primary,
  .secondary,
  .danger {
    min-height: 44px;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 720px;
  }

  th,
  td {
    padding: 9px 10px;
    font-size: 13px;
  }

  .status-select {
    min-width: 140px;
  }

  .record-actions {
    gap: 6px;
  }

  .record-actions button,
  .small {
    padding: 8px 9px;
    min-height: 42px;
  }

  dialog {
    width: calc(100vw - 14px);
    max-height: calc(100vh - 14px);
    border-radius: 8px;
  }

  .dialog-box {
    min-width: 0;
    max-height: calc(100vh - 14px);
    overflow: auto;
    padding: 0;
  }

  .dialog-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #ffffff;
  }

  .dialog-actions {
    display: grid;
    width: 100%;
    margin-top: 12px;
  }

  #closePhotosButton {
    order: -1;
  }

  .dialog-actions button {
    width: 100%;
  }

  .dialog-head .secondary {
    width: 100%;
  }

  .service-form {
    padding-bottom: 16px;
  }
}
