:root {
  color-scheme: light;
  --page: #f0f4f2;
  --surface: #ffffff;
  --soft: #f6f8f7;
  --text: #18211d;
  --muted: #68736d;
  --line: #d9e1dd;
  --line-strong: #c4d0ca;
  --green: #17694f;
  --green-dark: #10533e;
  --green-soft: #e3f0ea;
  --blue: #2d6392;
  --blue-soft: #e8f0f7;
  --coral: #9a5148;
  --coral-soft: #f7eae8;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  overflow: hidden;
  color: var(--text);
  background: var(--page);
  font-size: 14px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button { color: inherit; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(23, 105, 79, 0.2);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 7px;
  color: #ffffff;
  background: var(--green);
  font-size: 17px;
  font-weight: 750;
}

.session-gate,
.service-gate {
  display: flex;
  width: 100%;
  height: 100dvh;
  padding: 24px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.session-gate h1,
.service-gate h1 {
  margin: 14px 0 0;
  font-size: 20px;
}

.loading-line {
  display: flex;
  margin-top: 16px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.loading-line > span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  animation: loading-pulse 1.1s ease-in-out infinite;
}

@keyframes loading-pulse {
  50% { opacity: 0.3; transform: scale(0.72); }
}

.service-gate p {
  margin: 9px 0 22px;
  color: var(--muted);
  line-height: 1.6;
}

.primary-button {
  display: inline-flex;
  min-height: 44px;
  padding: 0 18px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--green);
  border-radius: 6px;
  color: #ffffff;
  background: var(--green);
  font-weight: 650;
  cursor: pointer;
}

.primary-button:hover { background: var(--green-dark); }
.primary-button:disabled { cursor: not-allowed; opacity: 0.58; }

.auth-shell {
  width: 100%;
  height: 100dvh;
  padding: max(30px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(30px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
}

.auth-brand {
  width: min(100%, 440px);
  margin: 0 auto;
  padding: 14px 2px 24px;
}

.auth-brand > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-brand > div strong { font-size: 18px; }

.auth-brand h1 {
  margin: 30px 0 0;
  font-size: 27px;
  line-height: 1.3;
}

.auth-brand p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.auth-panel {
  width: min(100%, 440px);
  margin: 0 auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(29, 48, 39, 0.09);
}

.auth-notice {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid #e2c8c4;
  border-radius: 6px;
  color: #7b3e37;
  background: var(--coral-soft);
  font-size: 12px;
  line-height: 1.5;
}

.auth-form header { margin-bottom: 22px; }

.auth-form header span {
  display: block;
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
}

.auth-form h2 {
  margin: 5px 0 0;
  font-size: 20px;
}

.field {
  display: block;
  margin-top: 15px;
}

.field > span:first-child {
  display: block;
  margin-bottom: 6px;
  color: #34433c;
  font-size: 11px;
  font-weight: 650;
}

.field em {
  color: var(--muted);
  font-size: 9px;
  font-style: normal;
  font-weight: 400;
}

.field input,
.field select,
.field textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: 0;
  color: var(--text);
  background: var(--surface);
}

.field textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 105, 79, 0.09);
}

.field > small {
  display: block;
  min-height: 0;
  margin-top: 5px;
  color: var(--coral);
  font-size: 10px;
}

.field-error input,
.field-error select,
.field-error textarea,
.field-error .password-field {
  border-color: var(--coral);
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
}

.password-field:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 105, 79, 0.09);
}

.password-field input {
  min-width: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.password-field input:focus { box-shadow: none; }

.password-field button {
  min-width: 54px;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--blue);
  background: var(--soft);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
}

.field-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.form-error {
  margin-top: 14px;
  padding: 10px 11px;
  border-left: 3px solid var(--coral);
  color: #743b35;
  background: var(--coral-soft);
  font-size: 11px;
  line-height: 1.5;
}

.submit-button {
  width: 100%;
  margin-top: 20px;
}

.link-button {
  display: block;
  width: 100%;
  min-height: 38px;
  margin-top: 8px;
  border: 0;
  color: var(--blue);
  background: transparent;
  font-size: 11px;
  cursor: pointer;
}

.secondary-button {
  display: inline-flex;
  min-height: 44px;
  padding: 0 18px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  font-weight: 650;
  cursor: pointer;
}

.workspace-shell {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: 64px minmax(0, 1fr) 66px;
  overflow: hidden;
  background: var(--page);
}

.app-header {
  position: relative;
  z-index: 4;
  display: grid;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  grid-template-columns: auto minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-brand .brand-mark {
  width: 32px;
  height: 32px;
  font-size: 14px;
}

.app-brand strong { display: none; }

.org-context {
  min-width: 0;
}

.org-context strong,
.org-context span {
  display: block;
}

.org-context strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-context span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.account-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid #bcd3c8;
  border-radius: 50%;
  color: var(--green-dark);
  background: var(--green-soft);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.workspace-content {
  min-height: 0;
  padding: 18px max(14px, env(safe-area-inset-right)) 26px max(14px, env(safe-area-inset-left));
  overflow-y: auto;
}

.workspace-content > header {
  display: flex;
  min-height: 42px;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.workspace-content > header h1 {
  margin: 0;
  font-size: 23px;
}

.workspace-content > header span {
  max-width: 55%;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-empty {
  display: flex;
  width: min(100%, 560px);
  min-height: 310px;
  margin: 18px auto 0;
  padding: 36px 24px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.empty-marker {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 7px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 23px;
}

.workspace-empty h2 {
  margin: 18px 0 0;
  font-size: 17px;
}

.workspace-empty p {
  max-width: 360px;
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.business-overview {
  width: min(100%, 760px);
  margin: 18px auto 0;
}

.business-overview > header {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.business-overview h2 {
  margin: 0;
  font-size: 17px;
}

.business-overview header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.compact-button {
  min-height: 40px;
  padding: 0 14px;
  flex: 0 0 auto;
  font-size: 12px;
}

.business-list {
  display: grid;
  padding: 14px 0 32px;
  gap: 10px;
}

.business-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.business-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.business-state span {
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--green-dark);
  background: var(--green-soft);
  font-size: 10px;
  font-weight: 700;
}

.business-state time {
  color: var(--muted);
  font-size: 10px;
}

.business-card h3 {
  margin: 12px 0 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.4;
}

.business-counterparty,
.business-objective {
  margin: 7px 0 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.business-objective {
  padding-top: 9px;
  border-top: 1px solid var(--line);
  color: #435149;
}

.main-nav {
  display: grid;
  min-height: 66px;
  padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.main-nav button {
  min-width: 0;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
  cursor: pointer;
}

.main-nav button[aria-selected="true"] {
  color: var(--green-dark);
  background: var(--green-soft);
  font-weight: 700;
}

.account-scrim {
  position: fixed;
  z-index: 19;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgba(20, 31, 26, 0.34);
}

.account-panel {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: min(82dvh, 620px);
  padding: 16px max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  border-top: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  box-shadow: 0 -18px 48px rgba(29, 48, 39, 0.16);
}

.business-dialog-layer {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.business-dialog-scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgba(20, 31, 26, 0.4);
}

.business-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: min(92dvh, 680px);
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  border-top: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  box-shadow: 0 -20px 50px rgba(20, 31, 26, 0.18);
}

.business-dialog > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.business-dialog > header small {
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
}

.business-dialog h2 {
  margin: 4px 0 0;
  font-size: 19px;
}

.business-dialog > header button {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 6px;
  background: var(--soft);
  font-size: 23px;
  cursor: pointer;
}

.business-dialog-copy {
  margin: 11px 0 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.business-dialog form footer {
  display: grid;
  margin-top: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px;
}

.business-dialog form footer .submit-button { margin: 0; }

.account-panel > header {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
}

.account-panel h2 { margin: 0; font-size: 16px; }

.account-panel > header button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: var(--soft);
  font-size: 23px;
  cursor: pointer;
}

.profile-block {
  display: flex;
  margin-top: 12px;
  padding: 15px 0;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--line);
}

.profile-block > span {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  color: var(--green-dark);
  background: var(--green-soft);
  font-weight: 700;
}

.profile-block strong,
.profile-block small {
  display: block;
}

.profile-block strong { font-size: 13px; }
.profile-block small { margin-top: 3px; color: var(--muted); font-size: 10px; }

.account-org {
  margin-top: 15px;
  padding: 14px;
  border-left: 3px solid var(--blue);
  background: var(--blue-soft);
}

.account-org small,
.account-org strong,
.account-org span {
  display: block;
}

.account-org small { color: var(--blue); font-size: 9px; font-weight: 700; }
.account-org strong { margin-top: 5px; overflow-wrap: anywhere; font-size: 13px; }
.account-org span { margin-top: 5px; color: var(--muted); font-size: 10px; }

.logout-button {
  width: 100%;
  min-height: 44px;
  margin-top: 18px;
  border: 1px solid #dfc3bf;
  border-radius: 6px;
  color: var(--coral);
  background: var(--surface);
  font-weight: 650;
  cursor: pointer;
}

.toast {
  position: fixed;
  z-index: 40;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  max-width: calc(100% - 28px);
  padding: 10px 14px;
  border-radius: 6px;
  color: #ffffff;
  background: #22322b;
  box-shadow: 0 10px 30px rgba(20, 31, 26, 0.2);
  font-size: 11px;
  text-align: center;
  transform: translateX(-50%);
}

@media (min-width: 720px) {
  .auth-shell {
    display: grid;
    padding: 48px;
    grid-template-columns: minmax(280px, 420px) minmax(360px, 440px);
    align-content: center;
    justify-content: center;
    gap: 70px;
  }

  .auth-brand,
  .auth-panel { width: 100%; margin: 0; }
  .auth-brand { align-self: center; padding: 0; }
  .auth-brand h1 { font-size: 35px; }

  .workspace-shell {
    grid-template-columns: 190px minmax(0, 1fr);
    grid-template-rows: 68px minmax(0, 1fr);
  }

  .app-header {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 10px 24px;
    grid-template-columns: 160px minmax(0, 1fr) 40px;
  }

  .app-brand strong { display: block; font-size: 16px; }
  .org-context { justify-self: end; width: min(360px, 45vw); text-align: right; }
  .org-context strong { font-size: 13px; }

  .main-nav {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    min-height: 0;
    padding: 18px 12px;
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .main-nav button {
    min-height: 46px;
    padding: 0 14px;
    text-align: left;
    font-size: 12px;
  }

  .main-nav button[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--green); }

  .workspace-content {
    grid-column: 2;
    grid-row: 2;
    padding: 28px 36px 44px;
  }

  .workspace-content > header,
  .workspace-empty,
  .business-overview { width: min(100%, 960px); margin-right: auto; margin-left: auto; }
  .workspace-empty { min-height: 390px; margin-top: 24px; }

  .account-panel {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(380px, calc(100% - 80px));
    max-height: none;
    padding: 22px 24px;
    border-top: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    box-shadow: -18px 0 48px rgba(29, 48, 39, 0.16);
  }

  .business-dialog-layer { align-items: center; padding: 28px; }

  .business-dialog {
    width: min(100%, 520px);
    max-height: calc(100dvh - 56px);
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 22px 62px rgba(20, 31, 26, 0.22);
  }

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

  .toast { bottom: 28px; }
}

@media (max-width: 360px) {
  .auth-shell { padding-right: 12px; padding-left: 12px; }
  .auth-brand { padding-top: 0; padding-bottom: 15px; }
  .auth-brand h1 { margin-top: 18px; font-size: 23px; }
  .auth-panel { padding: 18px 16px; }
  .auth-form header { margin-bottom: 14px; }
  .field { margin-top: 11px; }
  .submit-button { margin-top: 15px; }
  .workspace-content { padding-top: 14px; }
  .workspace-empty { min-height: 280px; padding: 24px 14px; }
  .business-overview > header { align-items: flex-start; }
  .business-overview h2 { font-size: 15px; }
  .compact-button { min-height: 38px; padding: 0 10px; }
  .business-dialog { padding-top: 14px; }
  .business-dialog .field { margin-top: 10px; }
  .business-dialog-copy { margin-top: 7px; }
  .business-dialog form footer { margin-top: 13px; }
  .main-nav button { font-size: 9px; }
}

@media (max-height: 620px) and (max-width: 719px) {
  .auth-shell { padding-top: 12px; padding-bottom: 12px; }
  .auth-brand { padding-bottom: 8px; }
  .auth-brand h1 { margin-top: 10px; font-size: 21px; }
  .auth-brand p { margin-top: 4px; }
  .auth-panel { padding-top: 14px; padding-bottom: 10px; }
  .auth-form header { margin-bottom: 8px; }
  .auth-panel .field { margin-top: 8px; }
  .auth-panel .field textarea { min-height: 64px; }
  .auth-panel .submit-button { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
