:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #16202b;
  --muted: #657385;
  --line: #dce4ee;
  --line-strong: #c7d2df;
  --blue: #2563a8;
  --blue-dark: #1d4f88;
  --green: #16724b;
  --green-soft: #e7f6ee;
  --amber: #99630d;
  --amber-soft: #fff3d8;
  --red: #b23b45;
  --red-soft: #fdecef;
  --shadow: 0 18px 40px rgba(31, 45, 61, 0.10);
  --shadow-soft: 0 1px 2px rgba(31, 45, 61, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8fafc 0, var(--bg) 360px);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

button:hover:not(:disabled) {
  border-color: #b5c3d2;
  box-shadow: 0 7px 18px rgba(31, 45, 61, 0.10);
  transform: translateY(-1px);
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

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

.primary:hover:not(:disabled) {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

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

.sidebar {
  background: #142334;
  color: #edf3f8;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 14px 0 32px rgba(20, 35, 52, 0.14);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 800;
  font-size: 18px;
}

.brand span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: #81c7a0;
  color: #0f2217;
  border-radius: 8px;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.12);
}

nav {
  display: grid;
  gap: 6px;
}

nav button {
  background: transparent;
  color: #c9d4df;
  border: 0;
  justify-content: flex-start;
  text-align: left;
  box-shadow: none;
  min-height: 42px;
}

nav button.active {
  background: #20384f;
  color: #fff;
  box-shadow: inset 3px 0 0 #81c7a0;
}

.sync {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
  background: rgba(255,255,255,.05);
}

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

main {
  min-width: 0;
  padding: 24px 30px 30px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  min-height: 56px;
}

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

.session-user {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
  letter-spacing: 0;
}

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

.grid {
  display: grid;
  grid-template-columns: minmax(340px, 520px) minmax(340px, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

.view {
  display: grid;
  gap: 18px;
}

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

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: #81c7a0;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
}

.stat strong {
  font-size: 25px;
  line-height: 1.15;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  align-items: start;
}

.detail {
  position: sticky;
  top: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

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

.search-panel {
  padding-bottom: 16px;
}

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

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

.overview-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 160px 170px;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.overview-filters label {
  padding: 0;
}

label {
  display: grid;
  gap: 7px;
  padding: 14px 16px 0;
  color: #405064;
  font-size: 13px;
  font-weight: 750;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 11px;
  background: #fbfcfe;
  color: var(--ink);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input:focus, select:focus {
  outline: 0;
  border-color: #80a9d7;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 168, 0.14);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.autocomplete {
  position: relative;
}

.autocomplete-menu {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.autocomplete-option {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 2px;
  padding: 8px 10px;
  text-align: left;
  font-weight: 400;
}

.autocomplete-option:last-child {
  border-bottom: 0;
}

.autocomplete-option:hover,
.autocomplete-option.active {
  background: #f2f7fc;
}

.autocomplete-option strong {
  font-weight: 700;
}

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

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 16px 0;
}

.form-actions button {
  min-width: 92px;
}

.line-editor {
  margin: 16px 16px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: visible;
  position: relative;
  z-index: 5;
  background: #fff;
}

.line-editor-head {
  min-height: 48px;
  padding: 8px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.subscription-lines {
  display: grid;
}

.subscription-line {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 120px 110px 150px 42px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.subscription-line:last-child {
  border-bottom: 0;
}

.subscription-line:focus-within {
  position: relative;
  z-index: 50;
  background: #fbfdff;
}

.subscription-line strong,
.subscription-line span {
  display: block;
}

.subscription-line span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.line-field {
  display: grid;
  gap: 5px;
}

.line-field span {
  margin-top: 0;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.empty-lines {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.ready {
  background: var(--green-soft);
  color: var(--green);
}

.badge.waiting {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.locked {
  background: #edf1f6;
  color: #4e5b6d;
}

.preview {
  padding: 16px;
  display: grid;
  gap: 12px;
}

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

.preview-card {
  border: 1px solid #c7d8eb;
  background: #f5f9fe;
  border-radius: 10px;
  padding: 14px;
}

.line-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.line-item + .line-item {
  margin-top: 8px;
}

.line-item strong {
  display: block;
  margin-bottom: 4px;
}

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

.actions {
  padding: 0 16px 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.subscription-log {
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fbfcfe;
}

.subscription-log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.subscription-log-list {
  display: grid;
}

.subscription-log-list.empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.subscription-log-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}

.subscription-log-item:last-child {
  border-bottom: 0;
}

.subscription-log-item strong,
.subscription-log-item span {
  display: block;
}

.subscription-log-item strong {
  font-size: 13px;
}

.subscription-log-item span,
.subscription-log-item time {
  color: var(--muted);
  font-size: 12px;
}

.subscription-log-item .log-order-number {
  color: var(--ink);
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 860px;
}

th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

th:nth-child(n+3),
td:nth-child(n+3) {
  white-space: nowrap;
}

tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

tbody tr:hover {
  background: #f8fbff;
}

tbody tr.selected {
  background: #eef6ff;
}

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

.delivery-address {
  margin-top: 7px;
  color: #405064;
  font-size: 12px;
  line-height: 1.35;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 380px;
  background: #142334;
  color: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 13px 15px;
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, #f8fafc 0%, #e9eff6 100%);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 15px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.login-logo {
  min-height: 68px;
  display: grid;
  place-items: center;
  margin-bottom: 2px;
}

.login-logo img {
  max-width: 220px;
  max-height: 68px;
  object-fit: contain;
}

.login-logo strong {
  color: var(--brand);
  font-size: 28px;
  letter-spacing: 0;
}

.login-card h2 {
  font-size: 22px;
  text-align: center;
}

.login-card p {
  margin-bottom: 0;
  text-align: center;
}

.login-card label {
  padding: 0;
}

@media (max-width: 1050px) {
  .app, .grid, .workspace {
    grid-template-columns: 1fr;
  }

  .detail {
    position: static;
  }

  .sidebar {
    padding: 16px;
  }

  nav {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .sync {
    display: none;
  }
}

@media (max-width: 760px) {
  .app {
    display: block;
    min-width: 0;
  }

  .sidebar {
    padding: 14px;
    gap: 14px;
  }

  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  nav button {
    padding: 0 8px;
    font-size: 13px;
  }

  main {
    padding: 16px;
  }

  header, .two {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

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

  .header-actions button {
    flex: 1;
  }

  .overview-filters {
    grid-template-columns: 1fr;
  }

  .subscription-line {
    grid-template-columns: 1fr;
  }

  .subscription-line .icon-button {
    width: 100%;
  }

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

  .stat {
    padding: 14px;
  }

  .stat strong {
    font-size: 22px;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 900px;
  }
}
