:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #697571;
  --line: #dfe6e3;
  --panel: #ffffff;
  --wash: #f7f9f8;
  --brand: #24584e;
  --brand-strong: #173c36;
  --accent: #b77934;
  --danger: #a33c2f;
  --ok: #2f7a4d;
  --soft: #eef3f1;
  --shadow: 0 16px 38px rgba(23, 32, 29, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--wash);
  color: var(--ink);
}

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

h1, h2, h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 { font-size: 26px; line-height: 1.15; }
h2 { font-size: 18px; line-height: 1.2; }
h3 { font-size: 15px; line-height: 1.25; }
p { color: var(--muted); line-height: 1.5; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--wash);
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--brand);
  font-weight: 800;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

label {
  font-size: 12px;
  font-weight: 750;
  color: #44514d;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 44px;
  padding: 10px 11px;
  background: white;
  color: var(--ink);
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(36, 88, 78, 0.18);
  border-color: var(--brand);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.btn {
  min-height: 44px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--soft);
  color: var(--ink);
  font-weight: 760;
}

.btn.primary { background: var(--brand); color: white; }
.btn.accent { background: var(--accent); color: white; }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: white; border: 1px solid var(--line); }
.btn.small { min-height: 36px; padding: 7px 11px; font-size: 13px; }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px 1fr;
}

.sidebar {
  background: var(--brand-strong);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar .brand-mark { margin-bottom: 18px; }
.sidebar .brand-icon { background: rgba(255, 255, 255, 0.14); }
.sidebar small { color: #bbcbc7; }

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

.nav button {
  width: 100%;
  min-height: 42px;
  color: #dce9e5;
  background: transparent;
  text-align: left;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.nav button.active, .nav button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.nav-group {
  display: grid;
  gap: 4px;
}

.nav-submenu {
  display: grid;
  gap: 3px;
  padding-left: 20px;
}

.nav-submenu button {
  min-height: 36px;
  color: #bfd0cc;
  font-size: 13px;
}

.nav-submenu button.active {
  background: rgba(255, 255, 255, 0.14);
  color: white;
}

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

.mobile-header, .mobile-tabbar, .mobile-menu {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

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

.user-pill {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 12px;
}

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

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel { padding: 16px; }
.card { padding: 14px; }

.stat {
  min-height: 98px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat strong {
  font-size: 26px;
  line-height: 1;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar .filters, .filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.list-row {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.row-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

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

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

.badge.ok { background: #e3f2e9; color: var(--ok); }
.badge.warn { background: #fff2dc; color: #98620e; }
.badge.danger { background: #fce8e4; color: var(--danger); }
.badge.info { background: #e3f3f6; color: #267284; }

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

.form-grid .full { grid-column: 1 / -1; }

.drawer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 30;
}

.drawer.open { display: block; }

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 16, 0.38);
}

.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: min(720px, 100%);
  background: var(--wash);
  box-shadow: var(--shadow);
  overflow: auto;
  padding: 18px;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 10px;
  min-height: 44px;
}

.checkline input {
  width: 18px;
  min-height: 18px;
}

.checkline.done {
  color: var(--muted);
  text-decoration: line-through;
}

.service-picker, .inventory-usage {
  display: grid;
  gap: 8px;
}

.quote-line {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 8px;
  align-items: center;
}

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

.notice {
  border-left: 4px solid #267284;
  background: #edf7f8;
  padding: 10px 12px;
  color: #26474c;
  border-radius: 6px;
}

.empty {
  border: 1px dashed #bdc8c4;
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
  background: white;
  text-align: center;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

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

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

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--brand-strong);
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 60;
}

.toast.show { display: block; }

@media (max-width: 980px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 16px 14px 92px;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -16px -14px 14px;
    padding: 12px 14px;
    background: rgba(247, 249, 248, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }

  .mobile-header div {
    display: grid;
    gap: 1px;
  }

  .mobile-header span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar-actions, .view-copy {
    display: none;
  }

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

  .grid.cols-3, .grid.cols-2 {
    grid-template-columns: 1fr;
  }

  .mobile-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    min-height: 66px;
    padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(23, 32, 29, 0.08);
  }

  .mobile-tabbar button {
    min-width: 0;
    border-radius: 6px;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    background: transparent;
    color: var(--muted);
    font-weight: 750;
  }

  .mobile-tabbar button span {
    font-size: 18px;
    line-height: 1;
  }

  .mobile-tabbar button small {
    font-size: 10px;
    line-height: 1.1;
  }

  .mobile-tabbar button.active {
    background: var(--soft);
    color: var(--brand);
  }

  .mobile-menu {
    position: fixed;
    inset: 0;
    z-index: 50;
  }

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

  .mobile-menu-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 18, 16, 0.34);
  }

  .mobile-menu-panel {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 14px;
  }

  .mobile-menu-list {
    display: grid;
    gap: 8px;
  }

  .mobile-menu-list button {
    min-height: 46px;
    border-radius: 6px;
    background: var(--soft);
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-weight: 760;
    text-align: left;
  }

  .mobile-menu-list button.active {
    background: var(--brand);
    color: white;
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    text-align: center;
  }
}

@media (max-width: 680px) {
  h2 { font-size: 17px; }

  .panel {
    padding: 14px;
  }

  .topbar, .toolbar, .row-head {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .btn.primary,
  .toolbar .btn.accent,
  .toolbar .btn {
    width: 100%;
  }

  .filters {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .filters .btn,
  .filters .badge {
    flex: 0 0 auto;
  }

  .form-grid,
  .quote-line,
  .split-row {
    grid-template-columns: 1fr;
  }

  .drawer-panel {
    inset: auto 0 0;
    height: min(92vh, 820px);
    width: 100%;
    border-radius: 8px 8px 0 0;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  }

  .drawer-backdrop {
    background: rgba(10, 18, 16, 0.28);
  }

  .stat {
    min-height: 86px;
  }

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

  .table, .table thead, .table tbody, .table tr, .table th, .table td {
    display: block;
  }

  .table thead {
    display: none;
  }

  .table {
    background: transparent;
    border-radius: 0;
  }

  .table tr {
    border: 1px solid var(--line);
    background: white;
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 8px;
  }

  .table td {
    border: 0;
    padding: 5px 2px;
  }
}
