/* Учёт заказов — демонстрационный проект. Самостоятельный интерфейс, не связанный со стилями сайта-портфолио. */

:root {
  --bg: #f4f5f9;
  --surface: #fff;
  --text: #1b1f27;
  --text-2: #5b6270;
  --muted: #7b8290;
  --line: #e4e7ee;
  --line-2: #cfd4df;
  --accent: #3556d8;
  --accent-hover: #2a46b8;
  --accent-soft: #e9edfb;
  --late: #c2410c;
  --late-soft: #fdebe1;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(20 24 40 / 0.05), 0 8px 24px -16px rgb(20 24 40 / 0.25);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-feature-settings: 'tnum';
}

body.has-drawer {
  overflow: hidden;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.late {
  color: var(--late);
  font-weight: 600;
}

/* ---------- каркас ---------- */

.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: 100vh;
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.side__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.side__logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.side__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.side__nav {
  display: grid;
  gap: 2px;
}

.side__nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
}

.side__nav a:hover {
  background: var(--bg);
  color: var(--text);
}

.side__nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.side__nav svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side__count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.side__nav a.is-active .side__count {
  background: #fff;
}

.side__user {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.side__hint {
  font-size: 12px;
  color: var(--muted);
}

.side__links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.main {
  width: 100%;
  max-width: 1180px;
  padding: 28px 32px 56px;
}

.tabs {
  display: none;
}

/* ---------- общие элементы ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.btn:hover {
  border-color: var(--text-2);
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}

.btn--ghost:hover {
  border-color: var(--line-2);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn--file {
  position: relative;
  overflow: hidden;
}

.btn--file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

.link:hover {
  text-decoration: underline;
}

.iconbtn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.iconbtn:hover {
  background: var(--bg);
}

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-style: normal;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.chip--demo {
  background: #fff3c4;
  color: #8a5a00;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chip--new {
  background: #e6eefc;
  color: #1d4fbf;
}

.chip--work {
  background: #fdf0d5;
  color: #92400e;
}

.chip--ready {
  background: #dcf5e3;
  color: #166534;
}

.chip--done {
  background: #eceef2;
  color: #4b5563;
}

.chip--cancel {
  background: #f3e8ea;
  color: #9f1239;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--text-2);
}

.field input,
.field select,
.search,
.select {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.field input:focus,
.field select:focus,
.search:focus,
.select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field--ro b {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.field--wide {
  grid-column: 1 / -1;
}

.card {
  min-width: 0; /* в сетке карточка может сжиматься: широкая таблица прокручивается внутри, а не растягивает страницу */
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card--soft {
  background: var(--surface);
}

.card__title {
  font-size: 15px;
  font-weight: 600;
}

.card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 12px;
}

.card p + .actions,
.card__title + .table,
.card__title + .list,
.card__title + p {
  margin-top: 12px;
}

.eyebrow {
  font-size: 12.5px;
  color: var(--muted);
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--late-soft);
  color: var(--late);
}

.empty {
  padding: 32px 0;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / 0.4);
  transform: translateX(-50%);
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* ---------- заголовок страницы и фильтры ---------- */

.page__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 20px;
}

.page__title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page__sub {
  margin-top: 2px;
  color: var(--text-2);
}

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

.search {
  flex: 1 1 260px;
  max-width: 420px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 12px;
}

.chipbtn {
  padding: 5px 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13.5px;
  cursor: pointer;
}

.chipbtn b {
  margin-left: 4px;
  font-weight: 600;
  color: var(--muted);
}

.chipbtn.is-on {
  border-color: var(--text);
  background: var(--text);
  color: #fff;
}

.chipbtn.is-on b {
  color: rgb(255 255 255 / 0.7);
}

/* ---------- реестр ---------- */

.rows {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 11px 18px;
  border-top: 1px solid var(--line);
  transition: background 0.12s;
}

.rows--nosum .row {
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 0.9fr);
}

.only-m {
  display: none;
}

.row--head {
  border-top: 0;
  padding-block: 10px;
  background: #f8f9fc;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

a.row:hover {
  background: #f8f9fc;
}

.row--late {
  box-shadow: inset 3px 0 0 var(--late);
}

.row .sub {
  display: block;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
}

.c-item b {
  font-weight: 600;
}

.c-sum {
  text-align: right;
  font-weight: 500;
}

/* ---------- карточка заказа ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgb(20 24 40 / 0.35);
  animation: fade 0.2s ease-out;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(520px, 100vw);
  background: var(--surface);
  box-shadow: -12px 0 40px -20px rgb(0 0 0 / 0.35);
  animation: slide 0.25s ease-out;
}

@keyframes slide {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}

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

.drawer__title {
  margin-top: 2px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.drawer__title:focus {
  outline: none;
}

.drawer__body {
  display: grid;
  gap: 20px;
  padding: 20px 24px 32px;
  overflow-y: auto;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.tg,
.history {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.tg h3,
.history h3 {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.tg__msg {
  position: relative;
  max-width: 34rem;
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: 14px 14px 14px 4px;
  background: #eef3ff;
  font-size: 14px;
  white-space: normal;
}

.tg__meta {
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
}

.tg__note {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.comment {
  display: flex;
  gap: 8px;
}

.comment input {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
}

.history__list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.history__list li {
  display: grid;
  gap: 2px;
  padding-left: 14px;
  border-left: 2px solid var(--line);
}

.history__list li.is-comment {
  border-left-color: var(--accent);
}

.history__meta {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- сводка ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  display: grid;
  gap: 2px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat__label {
  font-size: 13px;
  color: var(--text-2);
}

.stat__value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat--late .stat__value {
  color: var(--late);
}

.stat__sub {
  font-size: 12.5px;
  color: var(--muted);
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.cards .card:first-child:nth-last-child(3) {
  grid-column: 1 / -1;
}

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th,
.table td {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.table th {
  border-top: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.table td:not(:first-child),
.table th:not(:first-child) {
  text-align: right;
}

.list {
  display: grid;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.list li {
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.list li:first-child {
  border-top: 0;
}

.list li a {
  display: grid;
  grid-template-columns: 6.5rem 1fr auto;
  gap: 12px;
  align-items: baseline;
}

.list li a:hover b {
  color: var(--accent);
}

.list--msgs li {
  display: grid;
  gap: 4px;
}

.list--msgs li span:first-child {
  font-size: 12px;
}

.foot {
  margin-top: 24px;
  font-size: 13px;
}

/* ---------- импорт: файл как таблица ---------- */

.sheet-wrap {
  margin: 14px -20px;
  padding: 0 20px;
  overflow-x: auto;
}

.sheet {
  min-width: 860px;
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--font);
}

.sheet th,
.sheet td {
  padding: 5px 8px;
  border: 1px solid #d7dbe4;
  white-space: nowrap;
}

.sheet th {
  width: 2.2rem;
  background: #eef0f5;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
}

.sheet thead tr:first-child th {
  height: 24px;
}

.sheet__names td {
  background: #f8f9fc;
  font-weight: 600;
}

.sheet td:last-child,
.sheet th.sheet__check {
  width: 1%;
  min-width: 16rem;
  white-space: normal;
}

.sheet__check {
  font-size: 12.5px;
}

.sheet tbody tr.is-ok .sheet__check {
  color: #166534;
}

.sheet tbody tr.is-bad td {
  background: #fff5f0;
}

.sheet tbody tr.is-bad .sheet__check {
  color: var(--late);
}

.sheet tbody tr.is-dup td {
  background: #f3f4f7;
  color: var(--muted);
}

/* ---------- телефон и планшет ---------- */

@media (max-width: 900px) {
  /* Верхняя панель вместо боковой: название слева, выбор пользователя справа; ничто не шире экрана */
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    position: sticky;
    z-index: 30;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    height: auto;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side__brand {
    flex: 0 1 auto;
    min-width: 0;
    padding: 0;
  }

  .side__nav,
  .side__hint,
  .side__links {
    display: none;
  }

  .side__title b {
    white-space: nowrap;
  }

  .side__user {
    flex: 0 1 auto;
    min-width: 0;
    margin-top: 0;
  }

  .side__user .field span {
    display: none;
  }

  .side__user .field select {
    width: 100%;
    min-height: 36px;
    max-width: 9.5rem;
    font-size: 13px;
  }

  .toast {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .main {
    min-width: 0;
    padding: 18px 16px 88px;
  }

  .tabs {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .tabs a {
    padding: 12px 8px;
    font-size: 13.5px;
    font-weight: 600;
    text-align: center;
    color: var(--text-2);
  }

  .tabs a.is-active {
    color: var(--accent);
    box-shadow: inset 0 2px 0 var(--accent);
  }

  .page__title {
    font-size: 22px;
  }

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

  .cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .drawer {
    top: auto;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .drawer__head {
    padding: 16px 18px 12px;
  }

  .drawer__body {
    padding: 16px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 720px) {
  /* Строка реестра превращается в карточку */
  .row {
    grid-template-columns: 1fr auto !important;
    grid-template-areas:
      'item status'
      'master due'
      'sum sum';
    gap: 6px 12px;
    padding: 12px 14px;
  }

  .row--head {
    display: none;
  }

  .c-item {
    grid-area: item;
  }

  .c-status {
    grid-area: status;
  }

  .c-client {
    display: none;
  }

  .only-m {
    display: inline;
  }

  .c-master {
    grid-area: master;
    font-size: 13.5px;
    color: var(--text-2);
  }

  .c-due {
    grid-area: due;
    font-size: 13.5px;
    text-align: right;
  }

  .c-sum {
    grid-area: sum;
    font-size: 13.5px;
    text-align: left;
  }

  /* У мастера нет колонки ответственного — срок занимает всю строку */
  .rows--nosum .c-due {
    grid-column: 1 / -1;
    text-align: left;
  }

  .c-due .sub,
  .c-sum .sub {
    display: inline;
    margin-left: 6px;
  }

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

  .list li a {
    grid-template-columns: 5.5rem 1fr;
  }

  .list li a span:last-child {
    grid-column: 2;
  }
}

/* Узкие телефоны: без квадрата-логотипа, чтобы название и выбор пользователя уместились в одну строку */
@media (max-width: 480px) {
  .side__logo {
    display: none;
  }

  .side__user .field select {
    max-width: 8.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drawer,
  .backdrop,
  .toast {
    animation: none;
  }
}
