:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #17212b;
  --muted: #647382;
  --line: #dbe2e8;
  --accent: #0f766e;
  --accent-2: #1f7a8c;
  --danger: #b42318;
  --warning: #b7791f;
  --ok: #18794e;
  --shadow: 0 12px 34px rgba(18, 31, 43, 0.08);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #15202b;
}
.login-screen.hidden { display: none; }
.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0,0,0,0.28);
}
.login-panel .brand-mark { margin-bottom: 4px; }
.login-panel h1 { font-size: 26px; }
.login-panel p { margin-bottom: 6px; }

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  background: #15202b;
  color: #e7edf2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 20px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: #f3f7f8;
  color: #15202b;
  font-weight: 800;
  border-radius: 8px;
}

.brand-title { font-weight: 800; font-size: 16px; }
.brand-subtitle { color: #aab8c4; font-size: 13px; margin-top: 2px; }

.nav { display: grid; gap: 6px; }
.nav-item {
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5df;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: #eef7f5; color: #0f4f49; font-weight: 700; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  color: #b7c3ce;
  font-size: 13px;
}
.status-dot, .user-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
h1 { margin: 0; font-size: 28px; line-height: 1.15; }
h2 { margin: 0; font-size: 17px; }
p { margin: 6px 0 0; color: var(--muted); }

.top-actions, .filter-row, .search-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.price-filter-row {
  flex: 1;
  justify-content: flex-end;
}
.price-filter-row input {
  min-width: min(620px, 48vw);
}
.price-filter-row select {
  max-width: 160px;
}

.icon-button, .text-button, .primary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
}
.icon-button { width: 38px; padding: 0; font-size: 18px; }
.text-button { color: var(--accent); font-weight: 700; }
.primary-button {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 700;
}
.primary-button:disabled { opacity: 0.55; cursor: not-allowed; }

.profile-menu {
  position: relative;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
}
.menu-caret { color: var(--muted); font-size: 12px; }
.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 12;
  min-width: 150px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.profile-dropdown button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--danger);
  text-align: left;
  padding: 0 10px;
}
.profile-dropdown button:hover { background: #fdecec; }

.view { display: none; }
.view.active { display: grid; gap: 16px; }

.grid { display: grid; gap: 16px; }
.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-layout { grid-template-columns: minmax(330px, 0.9fr) minmax(420px, 1.1fr); align-items: start; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head.filters { align-items: center; }
.price-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  padding: 10px 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
}
.metric {
  padding: 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 27px; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #f8fafb;
  white-space: nowrap;
}
tbody tr:hover { background: #f7fbfb; }
.row-button { border: 0; background: transparent; color: var(--accent-2); font-weight: 700; padding: 0; }
.price-input {
  width: 118px;
  min-height: 32px;
  padding: 5px 8px;
  text-align: right;
}
.price-check {
  width: 16px;
  min-height: 16px;
}
.price-actionbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}
.price-selection, .price-actions, .row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.row-actions {
  gap: 8px;
  white-space: nowrap;
}
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.segment {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.segment.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.compact-select {
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.icon-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.tool-icon {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-2);
  font-weight: 800;
}
.tool-icon:hover { background: #eef7f5; }
.tool-icon.danger { color: var(--danger); }
.product-link { text-align: left; }
.checkline {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.checkline input { width: 16px; min-height: 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.ok { background: #e8f7ef; color: var(--ok); }
.badge.warn { background: #fff6df; color: var(--warning); }
.badge.danger { background: #fdecec; color: var(--danger); }

.bars, .compact-list, .info-list { padding: 14px 16px; display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 40px; gap: 10px; align-items: center; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }
.compact-item, .info-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.compact-item:last-child, .info-list div:last-child { border-bottom: 0; }
.compact-item span, .info-list span { color: var(--muted); }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}
select {
  appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, #647382 50%),
    linear-gradient(135deg, #647382 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 16px,
    calc(100% - 12px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select:focus, input:focus, textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.16);
  border-color: var(--accent);
}
textarea { resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
label input, label select, label textarea { color: var(--ink); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px; }
.wide-label { padding: 0 16px 16px; }

.package-results {
  max-height: 270px;
  overflow: auto;
  border-top: 1px solid var(--line);
}
.package-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 11px 16px;
  text-align: left;
}
.package-card:hover, .package-card.active { background: #eef7f5; }
.package-card strong { display: block; }
.package-card span { color: var(--muted); font-size: 13px; }
.line-editor { padding: 14px 16px; display: grid; gap: 12px; }
.selected-product {
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  color: var(--muted);
}
.upload-box {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.no-pad { padding: 0; }
.span-2 { grid-column: span 2; }

.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 33, 43, 0.42);
}
.modal-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.28);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}
.modal-body.hidden { display: none; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.directory-block {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
.directory-block h3 {
  margin: 0;
  font-size: 15px;
}
.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}
.directory-block .table-wrap {
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.directory-block table {
  font-size: 13px;
}
.directory-block th,
.directory-block td {
  padding: 8px 10px;
  vertical-align: middle;
}
.directory-block td:last-child,
.directory-block th:last-child {
  width: 88px;
  text-align: right;
}
.directory-block .icon-actions {
  justify-content: flex-end;
}
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafb;
  font-size: 13px;
  font-weight: 700;
}

.totals {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.total-pill {
  display: grid;
  gap: 3px;
  min-width: 150px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.total-pill span { color: var(--muted); font-size: 12px; }
.total-pill strong { font-size: 16px; }

.detail-panel:empty { display: none; }
.detail-body { padding: 16px; display: grid; gap: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.detail-card { padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.detail-card span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar-footer { display: none; }
  .two, .form-layout, .metric-grid { grid-template-columns: 1fr; }
  .price-actionbar, .price-selection, .price-actions { align-items: stretch; flex-direction: column; }
  .price-head { grid-template-columns: 1fr; }
  .price-filter-row { width: 100%; align-items: stretch; flex-direction: column; }
  .price-filter-row input { min-width: 0; }
  .price-filter-row select { max-width: none; }
  .topbar { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
