:root {
  color-scheme: light;
  --teal-900: #064e4a;
  --teal-700: #087d70;
  --teal-600: #0b9484;
  --teal-100: #d9f3ef;
  --ink: #172826;
  --muted: #60716e;
  --line: #d7e1df;
  --paper: #ffffff;
  --canvas: #f3f7f6;
  --danger: #b42318;
  --shadow: 0 12px 36px rgba(16, 57, 52, .09);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--canvas); font: 16px/1.45 "Segoe UI", Arial, sans-serif; }
button, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
[hidden] { display: none !important; }
input, select { font: inherit; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #e8f5f2, #f5f8f7 55%, #d6ece8); }
.login-card { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: 0 18px 55px rgba(6,78,74,.14); }
.login-card h1 { margin: 15px 0 4px; color: var(--teal-900); font-size: 1.6rem; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; margin: 13px 0 6px; font-weight: 700; }
.login-card input, .create-user-form input, .create-user-form select { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid #aebfbc; border-radius: 8px; background: #fbfdfd; }
.login-card .button { width: 100%; margin-top: 18px; }
.form-error { min-height: 24px; margin: 12px 0 0 !important; color: var(--danger) !important; font-size: .9rem; }

.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 clamp(18px, 4vw, 56px); color: white; background: linear-gradient(105deg, var(--teal-900), var(--teal-700)); box-shadow: 0 4px 18px rgba(6, 78, 74, .2); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; color: var(--teal-900); background: white; font-weight: 900; font-size: 1.35rem; }
.brand strong { display: block; font-size: 1.25rem; line-height: 1.1; letter-spacing: .02em; }
.brand small { display: block; margin-top: 3px; color: #c7ebe5; font-size: .78rem; }
.connection { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 7px 12px; border: 1px solid rgba(255,255,255,.28); border-radius: 999px; font-size: .88rem; }
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #ffc857; }
.connection.ready .connection-dot { background: #75e6a3; box-shadow: 0 0 0 4px rgba(117,230,163,.16); }
.connection.error .connection-dot { background: #ff8b82; }
.header-tools { display: flex; align-items: center; gap: 9px; }
.header-button { min-height: 34px; padding: 6px 10px; color: white; border: 1px solid rgba(255,255,255,.32); border-radius: 7px; background: rgba(255,255,255,.08); }
.header-button:hover { background: rgba(255,255,255,.16); }
.current-user { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }

.workspace { width: min(1480px, calc(100% - 32px)); margin: 24px auto 48px; }
.setup-notice { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 16px; padding: 14px 16px; border: 1px solid #e8c76a; border-left: 4px solid #c59209; border-radius: 10px; background: #fff9e8; }
.setup-notice[hidden] { display: none; }
.setup-notice p { margin: 3px 0 0; color: #685827; font-size: .9rem; }
.setup-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.setup-actions a { display: inline-flex; align-items: center; text-decoration: none; }

.lookup { display: grid; grid-template-columns: 1.45fr 1fr; gap: 16px; }
.field { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: var(--shadow); }
.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.field-heading label { font-weight: 700; }
.field-heading span { color: var(--muted); font-size: .84rem; }
textarea { display: block; width: 100%; min-height: 142px; resize: vertical; padding: 12px 13px; color: var(--ink); border: 1px solid #b9c8c5; border-radius: 8px; background: #fbfdfd; outline: 0; }
textarea:focus { border-color: var(--teal-600); box-shadow: 0 0 0 3px rgba(11,148,132,.14); }
textarea::placeholder { color: #879692; }

.actions { display: grid; grid-template-columns: auto auto minmax(160px, 1fr); align-items: center; gap: 10px; padding: 16px 2px 14px; }
.button { min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 8px; font-weight: 700; }
.button.primary { color: white; background: var(--teal-700); }
.button.primary:hover:not(:disabled) { background: var(--teal-900); }
.button.secondary { color: var(--teal-900); border-color: #a9bfbb; background: white; }
.button.secondary:hover:not(:disabled) { border-color: var(--teal-700); background: #edf8f6; }
.progress-shell { height: 8px; overflow: hidden; border-radius: 99px; background: #dfe8e6; }
.progress { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal-600), #31bca9); transition: width .18s ease; }
.status { grid-column: 1 / -1; margin: -2px 0 0; color: var(--muted); font-size: .9rem; }

.results-card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: var(--shadow); }
.results-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.results-heading h1 { margin: 0; font-size: 1.05rem; }
.results-heading span { color: var(--muted); font-size: .88rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 940px; border-collapse: collapse; }
th { padding: 10px 12px; color: #38504c; background: #edf4f3; border-bottom: 1px solid #cdd9d7; text-align: left; font-size: .83rem; letter-spacing: .02em; }
td { padding: 11px 12px; border-bottom: 1px solid #e4eae9; vertical-align: middle; }
tr.group-alt td { background: #f9fbfb; }
tr.group-end td { border-bottom: 2px solid #a9bfbb; }
tr.error td { color: var(--danger); background: #fff7f6; }
td.order { width: 190px; font-weight: 700; }
td.manager { font-weight: 700; color: var(--teal-900); }
.phone-button { min-width: 132px; padding: 7px 10px; color: #075f57; border: 1px solid #9bcfc8; border-radius: 7px; background: #eaf8f6; font-weight: 800; text-align: left; }
.phone-button:hover { border-color: var(--teal-700); background: var(--teal-100); }
.empty { padding: 54px 20px; color: var(--muted); text-align: center; }
.empty[hidden] { display: none; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(440px, calc(100vw - 44px)); padding: 12px 16px; color: white; border-radius: 9px; background: #183c38; box-shadow: 0 10px 30px rgba(0,0,0,.2); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.users-dialog { width: min(1000px, calc(100% - 30px)); max-height: 86vh; padding: 0; border: 0; border-radius: 14px; box-shadow: 0 24px 70px rgba(0,0,0,.24); }
.users-dialog::backdrop { background: rgba(6,34,31,.48); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; font-size: 1.15rem; }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 8px; background: #edf4f3; font-size: 1.4rem; }
.create-user-form { display: grid; grid-template-columns: 1fr 1fr 1.2fr .8fr auto; gap: 9px; padding: 16px 18px 4px; }
.users-dialog > .form-error { padding: 0 18px; }
.users-table { min-width: 760px; }
.row-actions { display: flex; gap: 7px; }
.mini-button { min-height: 34px; padding: 6px 9px; color: var(--teal-900); border: 1px solid #a9bfbb; border-radius: 7px; background: white; }

@media (max-width: 820px) {
  .topbar { height: auto; min-height: 68px; padding-block: 12px; }
  .brand small { display: none; }
  .connection { padding-inline: 9px; }
  .workspace { width: min(100% - 20px, 1480px); margin-top: 14px; }
  .lookup { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr 1fr; }
  .progress-shell { grid-column: 1 / -1; }
  .setup-notice { align-items: flex-start; flex-direction: column; gap: 10px; }
  .setup-actions { width: 100%; flex-wrap: wrap; }
  .header-tools { flex-wrap: wrap; justify-content: flex-end; }
  .current-user { display: none; }
  .create-user-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .brand strong { font-size: 1.05rem; }
  .connection strong { font-size: .78rem; }
  .connection { display: none; }
  .header-button { font-size: .82rem; }
  .field { padding: 12px; }
  .actions { grid-template-columns: 1fr; }
  .progress-shell, .status { grid-column: 1; }
  .create-user-form { grid-template-columns: 1fr; }
}
