/* BrikCRM Mobile — отдельный mobile-first слой, без desktop home.css */

:root {
  color-scheme: light dark;
  --m-safe-top: env(safe-area-inset-top, 0px);
  --m-safe-bottom: env(safe-area-inset-bottom, 0px);
  --m-header-safe-top: max(var(--m-safe-top), 14px);
  --m-nav-h: 3.5rem;
  --m-header-h: 3rem;
  --m-chat-switcher-h: 62px;
  --m-chat-panel-safe-bottom: min(var(--m-safe-bottom), 6px);
  --m-chat-bottom-gap: 4px;
  --m-chat-compose-lift: 10px;
  --m-chat-composer-h: 54px;
  --m-keyboard-inset: 0px;
  --m-visual-viewport-height: 100dvh;
  --m-radius: 14px;
  --m-radius-sm: 10px;
  --m-touch: 48px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html[data-theme="light"] {
  --m-bg: #f6f8f5;
  --m-surface: #ffffff;
  --m-elevated: rgba(255, 255, 255, 0.86);
  --m-text: #0f172a;
  --m-muted: #64748b;
  --m-border: rgba(15, 23, 42, 0.1);
  --m-accent: #32a852;
  --m-accent-soft: #e6f4ea;
  --m-chat-wallpaper: #dbeed6;
  --m-bubble-out: #dcf8c6;
  --m-bubble-in: #ffffff;
  --m-danger: #dc2626;
  --m-ios-blue: #2481cc;
  --m-chat-canvas-mid: #dbeed6;
  --m-chat-bg-image: url("/assets/chat-bg.svg");
  --m-chat-pattern-overlay: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.38) 0%,
    rgba(255, 255, 255, 0.12) 48%,
    rgba(0, 0, 0, 0.04) 100%
  );
  --m-chat-after-overlay:
    radial-gradient(ellipse 95% 45% at 50% 0%, rgba(255, 255, 255, 0.22), transparent 52%),
    radial-gradient(ellipse 90% 50% at 50% 100%, rgba(0, 0, 0, 0.06), transparent 55%);
}

html[data-theme="dark"] {
  --m-bg: #07130e;
  --m-surface: #0f172a;
  --m-elevated: rgba(15, 23, 42, 0.88);
  --m-text: #f8fafc;
  --m-muted: #94a3b8;
  --m-border: rgba(226, 232, 240, 0.12);
  --m-accent: #5ed083;
  --m-accent-soft: rgba(94, 208, 131, 0.15);
  --m-chat-wallpaper: #10251a;
  --m-bubble-out: #1f5f3d;
  --m-bubble-in: #182336;
  --m-danger: #f87171;
  --m-ios-blue: #64b5f6;
  --m-chat-canvas-mid: #0b141a;
  --m-chat-bg-image: url("/assets/chat-bg.svg");
  --m-chat-pattern-overlay: linear-gradient(
    180deg,
    rgba(15, 23, 42, 0.82) 0%,
    rgba(15, 23, 42, 0.45) 45%,
    rgba(0, 0, 0, 0.35) 100%
  );
  --m-chat-after-overlay:
    radial-gradient(ellipse 95% 45% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 52%),
    radial-gradient(ellipse 90% 50% at 50% 100%, rgba(0, 0, 0, 0.45), transparent 55%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  background:
    radial-gradient(circle at 16% -10%, rgba(50, 168, 82, 0.13), transparent 34%),
    linear-gradient(180deg, #fbfcfb 0%, var(--m-bg) 36%, #eff5ee 100%);
  color: var(--m-text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 16% -10%, rgba(94, 208, 131, 0.14), transparent 34%),
    linear-gradient(180deg, #0b1711 0%, var(--m-bg) 100%);
}

#m-root {
  height: 100%;
  height: 100dvh;
  height: var(--m-visual-viewport-height, 100dvh);
}

/* ----- Shell ----- */
.m-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  height: var(--m-visual-viewport-height, 100dvh);
  max-height: var(--m-visual-viewport-height, 100dvh);
  overflow: hidden;
}

.m-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: calc(var(--m-header-h) + var(--m-header-safe-top));
  padding: calc(0.28rem + var(--m-header-safe-top)) max(0.75rem, env(safe-area-inset-right)) 0.34rem
    max(0.75rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--m-elevated) 84%, transparent);
  border-bottom: 1px solid var(--m-border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(24px) saturate(1.35);
  -webkit-backdrop-filter: blur(24px) saturate(1.35);
  z-index: 10;
}

.m-header--thread {
  gap: 0.42rem;
  background-color: var(--m-chat-canvas-mid);
  background-image: var(--m-chat-pattern-overlay), var(--m-chat-bg-image);
  background-repeat: no-repeat, no-repeat;
  background-size: 100% 100%, cover;
  background-position: 0 0, center top;
  border-bottom-color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.m-header--thread .m-header__back,
.m-header--thread .m-header__center,
.m-header--thread .m-header__avatar {
  background: color-mix(in srgb, var(--m-elevated) 78%, transparent);
  border: 1px solid color-mix(in srgb, var(--m-border) 76%, transparent);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.09);
  backdrop-filter: blur(16px) saturate(1.18);
  -webkit-backdrop-filter: blur(16px) saturate(1.18);
}

.m-header--thread .m-header__back {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.3rem;
}

.m-header--thread .m-header__center {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 13.5rem;
  justify-self: center;
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
}

.m-header--thread .m-header__title {
  font-size: 0.92rem;
  line-height: 1.08;
}

.m-header--thread .m-header__subtitle {
  margin-top: 0.02rem;
  font-size: 0.66rem;
}

.m-header__back {
  flex: 0 0 auto;
  width: 2.55rem;
  height: 2.55rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--m-ios-blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  font-weight: 500;
  cursor: pointer;
}

.m-header__back[hidden] {
  display: none !important;
}

.m-header__center {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
}

.m-header__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-header__subtitle {
  margin-top: -0.08rem;
  color: var(--m-muted);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-header__action {
  flex: 0 0 auto;
  min-width: 2.55rem;
  min-height: 2.55rem;
  padding: 0 0.65rem;
  border: none;
  border-radius: 999px;
  background: var(--m-accent-soft);
  color: var(--m-accent);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.m-header__refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-header__create {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--m-accent);
}

.m-header__create[hidden] {
  display: none !important;
}

.m-header__delivery-calc[hidden] {
  display: none !important;
}

.m-header__refresh[hidden] {
  display: none !important;
}

.m-header__create:disabled,
.m-header__refresh:disabled {
  opacity: 0.58;
}

.m-header__create svg,
.m-header__delivery-calc svg,
.m-header__refresh svg {
  display: block;
}

.m-header__avatar {
  position: relative;
  overflow: hidden;
  width: 2.55rem;
  padding: 0;
  background: linear-gradient(135deg, #6ec6ff, #32a852);
  color: #fff;
  font-weight: 800;
  cursor: default;
  opacity: 1;
}

.m-header--thread .m-header__avatar {
  width: 2.25rem;
  min-width: 2.25rem;
  height: 2.25rem;
}

.m-header__avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.m-header__avatar--has-img .m-header__avatar-img {
  display: block;
}

.m-header__avatar-ph {
  position: relative;
  z-index: 1;
}

.m-header__avatar--has-img .m-header__avatar-ph {
  opacity: 0;
}

.m-main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.m-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.65rem max(0.65rem, env(safe-area-inset-right)) 0.75rem max(0.65rem, env(safe-area-inset-left));
}

.m-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 0.15rem;
  min-height: calc(var(--m-nav-h) + min(var(--m-safe-bottom), 0.45rem));
  padding: 0.2rem 0.35rem calc(0.18rem + min(var(--m-safe-bottom), 0.45rem));
  background: color-mix(in srgb, var(--m-elevated) 88%, transparent);
  border-top: 1px solid var(--m-border);
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(24px) saturate(1.25);
  -webkit-backdrop-filter: blur(24px) saturate(1.25);
}

.m-nav__btn {
  flex: 1 1 0;
  min-width: 0;
  max-width: 6.5rem;
  margin: 0;
  padding: 0.25rem 0.15rem;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--m-muted);
  font: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

.m-nav__icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-nav__badge {
  position: absolute;
  top: -0.35rem;
  right: -0.55rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.1rem;
  text-align: center;
  box-shadow: 0 0 0 2px var(--m-surface);
}

.m-nav__btn svg {
  width: 24px;
  height: 24px;
  opacity: 0.85;
}

.m-nav__btn--active {
  color: var(--m-accent);
  background: var(--m-accent-soft);
}

.m-nav__btn--active svg {
  opacity: 1;
}

body.m-keyboard-open .m-nav {
  display: none !important;
}

body.m-delivery-calc-open {
  overflow: hidden;
}

.m-delivery-calc-modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: grid;
  align-items: stretch;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  padding: max(0.55rem, var(--m-safe-top)) max(0.55rem, env(safe-area-inset-right))
    max(0.55rem, var(--m-safe-bottom)) max(0.55rem, env(safe-area-inset-left));
}

.m-delivery-calc-modal[hidden] {
  display: none !important;
}

.m-delivery-calc-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.m-delivery-calc-modal__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--m-border);
  border-radius: 22px;
  background: var(--m-surface);
  box-shadow: 0 24px 76px rgba(2, 6, 23, 0.34);
}

.m-delivery-calc-modal__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 3.1rem;
  padding: 0.58rem 0.72rem;
  border-bottom: 1px solid var(--m-border);
  background: color-mix(in srgb, var(--m-elevated) 92%, transparent);
}

.m-delivery-calc-modal__back,
.m-delivery-calc-modal__title {
  min-width: 0;
}

.m-delivery-calc-modal__back {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--m-ios-blue);
  font: inherit;
  font-size: 1.45rem;
  line-height: 1;
}

.m-delivery-calc-modal__title {
  flex: 1 1 auto;
  color: var(--m-text);
  font-size: 0.98rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-delivery-calc-modal__close {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--m-border);
  border-radius: 999px;
  background: var(--m-surface);
  color: var(--m-text);
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
}

.m-delivery-calc-modal__frame {
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  border: 0;
  background: #f4f6f8;
}

/* ----- Primitives ----- */
.m-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--m-touch);
  padding: 0 1rem;
  border: none;
  border-radius: var(--m-radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
}

.m-btn--primary {
  background: var(--m-accent);
  color: #fff;
}

.m-btn--ghost {
  background: transparent;
  color: var(--m-accent);
  border: 1px solid var(--m-border);
}

.m-btn--block {
  width: 100%;
}

.m-card {
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.65rem;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
}

.m-card__title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.m-card__meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--m-muted);
}

.m-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--m-accent-soft);
  color: var(--m-accent);
}

.m-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--m-muted);
  font-size: 0.92rem;
}

/* ----- Estimates ----- */
.m-estimates {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(0.9rem + var(--m-safe-bottom));
}

.m-estimates,
.m-estimates * {
  box-sizing: border-box;
}

.m-estimates--detail {
  position: absolute;
  inset: 0;
  display: block;
  height: auto;
  padding: 0.65rem max(0.65rem, env(safe-area-inset-right)) calc(0.9rem + var(--m-safe-bottom))
    max(0.65rem, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.m-estimates-hero {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.95rem;
  border: 1px solid var(--m-border);
  border-radius: 18px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--m-surface) 94%, var(--m-accent-soft)), var(--m-surface));
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.m-estimates-hero > div:first-child {
  min-width: 0;
}

.m-estimates-hero h2 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.m-estimates-hero p {
  margin: 0.22rem 0 0;
  color: var(--m-muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.m-estimates-hero .m-btn {
  white-space: nowrap;
}

.m-estimates-hero__actions {
  flex: 0 0 auto;
  align-self: center;
  display: grid;
  gap: 0.45rem;
}

.m-estimates-hero__actions .m-btn {
  min-width: 7.5rem;
}

.m-estimates-search {
  min-width: 0;
  padding: 0.66rem;
  border: 1px solid var(--m-border);
  border-radius: 16px;
  background: var(--m-surface);
}

.m-estimate-field,
.m-estimate-product-edit,
.m-estimate-item__grid label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-width: 0;
  color: var(--m-muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.m-estimates-search input,
.m-estimate-field input,
.m-estimate-field select,
.m-estimate-product-edit input,
.m-estimate-item__grid input,
.m-est-sheet__search {
  width: 100%;
  min-height: 46px;
  padding: 0.62rem 0.72rem;
  border: 1px solid var(--m-border);
  border-radius: 13px;
  background: var(--m-surface);
  color: var(--m-text);
  font: inherit;
  font-size: 0.96rem;
}

.m-search-field {
  position: relative;
  display: block;
  min-width: 0;
}

.m-search-field input {
  padding-right: 2.85rem !important;
}

.m-search-field__clear {
  position: absolute;
  top: 50%;
  right: 0.38rem;
  width: 2.05rem;
  height: 2.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-50%);
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-muted) 13%, transparent);
  color: var(--m-muted);
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
}

.m-search-field__clear[hidden] {
  display: none !important;
}

.m-search-field__clear:active {
  transform: translateY(-50%) scale(0.96);
}

.m-estimates-search input {
  min-height: 44px;
  background: color-mix(in srgb, var(--m-surface) 92%, var(--m-bg));
}

.m-estimates-list {
  display: grid;
  gap: 0.8rem;
  min-width: 0;
}

.m-estimate-list-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.65rem;
  width: 100%;
  min-width: 0;
  padding: 0.82rem 0.9rem;
  border: 1px solid var(--m-border);
  border-radius: 18px;
  background: var(--m-surface);
  color: var(--m-text);
  font: inherit;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}

.m-estimate-list-card__open {
  display: grid;
  gap: 0.38rem;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.m-estimate-list-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.7rem;
  min-width: 0;
}

.m-estimate-list-card__head strong,
.m-estimate-list-card__meta,
.m-estimate-list-card__address {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-estimate-list-card__head strong {
  font-size: 0.98rem;
  font-weight: 850;
  white-space: nowrap;
}

.m-estimate-list-card__author {
  color: var(--m-muted);
  font-weight: 700;
}

.m-estimate-list-card__side {
  flex: 0 0 auto;
  display: grid;
  justify-items: end;
  gap: 0.32rem;
  min-width: 4.8rem;
}

.m-estimate-list-card__side b {
  color: var(--m-accent);
  font-size: 0.94rem;
  white-space: nowrap;
}

.m-estimate-list-card__delete {
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid color-mix(in srgb, var(--m-danger) 22%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-danger) 10%, transparent);
  color: var(--m-danger);
  font: inherit;
}

.m-estimate-list-card__delete:active {
  transform: translateY(1px);
}

.m-estimate-list-card__meta,
.m-estimate-list-card__address {
  color: var(--m-muted);
  font-size: 0.82rem;
  line-height: 1.25;
  white-space: nowrap;
}

.m-estimates-empty {
  margin: 0.25rem 0;
  text-align: center;
}

.m-estimate-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--m-border);
  border-radius: 20px;
  background: var(--m-surface);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.07);
}

.m-estimate-card__top {
  display: grid;
  gap: 0.62rem;
  padding: 0.82rem;
  background: color-mix(in srgb, var(--m-accent-soft) 48%, transparent);
  border-bottom: 1px solid var(--m-border);
}

.m-estimate-items {
  display: grid;
  gap: 0.62rem;
  padding: 0.75rem;
}

.m-estimate-item {
  display: grid;
  gap: 0.55rem;
  padding: 0.65rem;
  border: 1px solid var(--m-border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--m-surface) 94%, var(--m-bg));
}

.m-estimate-product {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.62rem 0.8rem;
  border: 1px solid var(--m-border);
  border-radius: 14px;
  background: var(--m-surface);
  color: var(--m-text);
  font: inherit;
  text-align: left;
}

.m-estimate-product-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: end;
  min-width: 0;
}

.m-estimate-product-edit {
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  gap: 0.45rem;
  align-items: center;
}

.m-estimate-product-edit .m-estimate-product__num {
  grid-area: auto;
}

.m-estimate-product__num {
  grid-area: num;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--m-accent-soft);
  color: var(--m-accent);
  font-weight: 800;
}

.m-estimate-product__title {
  grid-area: title;
  min-width: 0;
  font-weight: 750;
  line-height: 1.25;
}

.m-estimate-product__meta {
  grid-area: meta;
  min-width: 0;
  color: var(--m-muted);
  font-size: 0.78rem;
}

.m-estimate-item__grid {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 0.55rem;
  align-items: end;
}

.m-estimate-item__sum {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-width: 0;
  color: var(--m-muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.m-estimate-item__sum strong {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 0.62rem 0.72rem;
  border: 1px solid var(--m-border);
  border-radius: 13px;
  background: var(--m-accent-soft);
  color: var(--m-accent);
  font-size: 0.96rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-estimate-row-delete {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: color-mix(in srgb, var(--m-danger) 12%, transparent);
  color: var(--m-danger);
  font: inherit;
  font-weight: 700;
}

.m-estimate-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0.75rem 0.75rem;
  padding: 0.75rem 0.82rem;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--m-accent-soft), color-mix(in srgb, var(--m-accent-soft) 48%, var(--m-surface)));
  color: var(--m-muted);
  font-weight: 800;
}

.m-estimate-total strong {
  color: var(--m-accent);
  font-size: 1.05rem;
}

.m-estimate-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0 0.75rem 0.8rem;
}

.m-estimate-actions .m-btn {
  min-width: 0;
  padding: 0 0.55rem;
  font-size: 0.84rem;
}

.m-estimate-danger {
  grid-column: 1 / -1;
  color: var(--m-danger) !important;
}

.m-est-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.m-est-sheet__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(2, 6, 23, 0.42);
}

.m-est-sheet__panel {
  position: relative;
  width: 100%;
  max-height: min(82vh, 720px);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.82rem max(0.82rem, env(safe-area-inset-right)) calc(0.9rem + var(--m-safe-bottom))
    max(0.82rem, env(safe-area-inset-left));
  border: 1px solid var(--m-border);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: var(--m-surface);
  box-shadow: 0 -18px 60px rgba(2, 6, 23, 0.22);
}

.m-est-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.m-est-sheet__head h3 {
  margin: 0;
  font-size: 1rem;
}

.m-est-sheet__head button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: var(--m-accent-soft);
  color: var(--m-accent);
  font-size: 1.35rem;
}

.m-est-sheet__list {
  min-height: 12rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--m-border);
  border-radius: 16px;
}

.m-est-picker-row {
  width: 100%;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.18rem;
  padding: 0.7rem 0.82rem;
  border: 0;
  border-bottom: 1px solid var(--m-border);
  background: transparent;
  color: var(--m-text);
  font: inherit;
  text-align: left;
}

.m-est-picker-row:last-child {
  border-bottom: 0;
}

.m-est-picker-row span,
.m-est-sheet__hint {
  color: var(--m-muted);
  font-size: 0.82rem;
}

.m-est-picker-row--back {
  color: var(--m-accent);
  font-weight: 800;
  background: var(--m-accent-soft);
}

.m-est-picker-row--seam {
  align-items: center;
  font-size: 1.1rem;
  font-weight: 850;
}

.m-est-sheet__hint {
  margin: 0;
  padding: 0.75rem 0.85rem;
}

.m-est-share-targets {
  display: grid;
  gap: 0.5rem;
}

.m-est-share-targets label {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--m-border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--m-surface) 94%, var(--m-bg));
  font-weight: 750;
}

@media (max-width: 380px) {
  .m-estimates-hero {
    flex-direction: column;
  }

  .m-estimates-hero__actions {
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .m-estimates-hero__actions .m-btn {
    min-width: 0;
  }

  .m-estimate-actions {
    grid-template-columns: 1fr;
  }
}

.m-error {
  padding: 0.75rem 1rem;
  border-radius: var(--m-radius-sm);
  background: rgba(220, 38, 38, 0.12);
  color: var(--m-danger);
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}

/* ----- Dashboard tiles ----- */
.m-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.m-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  min-height: 5.5rem;
  padding: 1rem 0.85rem;
  border: none;
  border-radius: var(--m-radius);
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  color: var(--m-text);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.05);
}

.m-tile__label {
  font-size: 0.95rem;
  font-weight: 700;
}

.m-tile__hint {
  font-size: 0.75rem;
  color: var(--m-muted);
  line-height: 1.35;
}

/* ----- Chat inbox ----- */
.m-scroll--inbox {
  padding: 0.25rem max(0.2rem, env(safe-area-inset-right)) 0.75rem max(0.2rem, env(safe-area-inset-left));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), transparent 8rem),
    var(--m-bg);
}

.m-inbox-list {
  overflow: hidden;
}

.m-inbox-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.72rem;
  padding: 0 0.9rem;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 76px;
  color: var(--m-text);
}

.m-inbox-item:active,
.m-inbox-item.is-active {
  background: rgba(50, 168, 82, 0.09);
}

.m-avatar {
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent),
    linear-gradient(135deg, #52b6ff, #30b566);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.02rem;
  box-shadow: 0 8px 18px rgba(30, 64, 175, 0.15);
}

.m-avatar img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.m-avatar--has-img img {
  opacity: 1;
}

.m-avatar__ph {
  position: relative;
  z-index: 1;
}

.m-avatar--has-img .m-avatar__ph {
  opacity: 0;
}

.m-inbox-item__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 76px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.m-inbox-item__top,
.m-inbox-item__bottom {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.m-inbox-item__title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-inbox-item__time {
  flex: 0 0 auto;
  color: var(--m-muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.m-inbox-item__sub {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.86rem;
  color: var(--m-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-inbox-item__badge {
  flex: 0 0 auto;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.38rem;
  border-radius: 999px;
  background: #34c759;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
}

/* ----- Chat thread ----- */
.m-thread {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background-color: var(--m-chat-canvas-mid);
  background-image: var(--m-chat-pattern-overlay), var(--m-chat-bg-image);
  background-repeat: no-repeat, no-repeat;
  background-size: 100% 100%, cover;
  background-position: 0 0, center center;
}

.m-thread::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--m-chat-after-overlay);
  background-repeat: no-repeat, no-repeat;
  background-size: 100% 100%, 100% 100%;
}

.m-thread::before {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--m-chat-switcher-h) + var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift));
  z-index: 0;
  pointer-events: none;
  background-color: var(--m-chat-canvas-mid);
  background-image: var(--m-chat-pattern-overlay), var(--m-chat-bg-image);
  background-repeat: no-repeat, no-repeat;
  background-size: 100% 100%, cover;
  background-position: 0 0, center bottom;
}

.m-thread > * {
  position: relative;
  z-index: 1;
}

.m-thread__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0.7rem max(0.55rem, env(safe-area-inset-right))
    calc(150px + var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift))
    max(0.55rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 0.34rem;
  overscroll-behavior: contain;
}

.m-pinned {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem max(0.65rem, env(safe-area-inset-right)) 0.42rem max(0.65rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--m-border);
  background: color-mix(in srgb, var(--m-elevated) 92%, transparent);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
}

.m-pinned[hidden] {
  display: none !important;
}

.m-pinned__jump {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  border-left: 3px solid var(--m-accent);
  background: transparent;
  color: var(--m-text);
  text-align: left;
  padding: 0.1rem 0 0.1rem 0.55rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-pinned__close {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.14);
  color: var(--m-muted);
  font-size: 1.3rem;
  line-height: 1;
}

.m-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.36rem;
  width: 100%;
  position: relative;
  transition:
    background-color 0.18s ease,
    transform 0.18s ease;
}

.m-msg-row--out {
  justify-content: flex-end;
}

.m-msg-row--in {
  justify-content: flex-start;
}

.m-msg-row--selected {
  background: rgba(36, 129, 204, 0.13);
  border-radius: 16px;
}

.m-msg-row--flash {
  animation: m-msg-flash 1.1s ease;
}

.m-msg-row__avatar {
  width: 30px;
  height: 30px;
  font-size: 0.72rem;
  box-shadow: 0 4px 10px rgba(30, 64, 175, 0.12);
}

.m-msg {
  position: relative;
  max-width: min(75%, 25rem);
  padding: 0.45rem 0.62rem 0.28rem;
  border-radius: 18px;
  font-size: 0.96rem;
  line-height: 1.32;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
  touch-action: manipulation;
  outline: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.m-msg :where(.m-msg__text, .m-msg__who, .m-msg__reply, .m-msg__forward, .m-msg__time, .m-msg-reactions) {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.m-msg--in {
  align-self: flex-start;
  background: var(--m-bubble-in);
  color: var(--m-text);
  border-bottom-left-radius: 6px;
}

.m-msg--out {
  align-self: flex-end;
  background: var(--m-bubble-out);
  color: #102115;
  border-bottom-right-radius: 6px;
}

html[data-theme="dark"] .m-msg--out {
  color: #f6fff8;
}

.m-msg__who {
  color: #1687d9;
  font-size: 0.76rem;
  font-weight: 800;
  margin: 0 0 0.12rem;
  letter-spacing: -0.01em;
}

.m-msg__reply,
.m-msg__forward {
  display: grid;
  gap: 0.1rem;
  width: 100%;
  margin: 0 0 0.28rem;
  padding: 0.34rem 0.48rem;
  border: 0;
  border-left: 3px solid var(--m-ios-blue);
  border-radius: 10px;
  background: rgba(36, 129, 204, 0.1);
  color: inherit;
  text-align: left;
}

.m-msg__reply-name,
.m-msg__forward strong {
  color: var(--m-ios-blue);
  font-size: 0.76rem;
  font-weight: 800;
}

.m-msg__reply-text,
.m-msg__forward span,
.m-msg__forward-quote {
  min-width: 0;
  overflow: hidden;
  color: var(--m-muted);
  font-size: 0.75rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.m-msg__forward-quote {
  margin-top: 0.12rem;
}

.m-msg__menu {
  position: absolute;
  top: -0.25rem;
  right: -0.25rem;
  width: 1.8rem;
  height: 1.8rem;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-elevated) 86%, transparent);
  color: var(--m-muted);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
  opacity: 0.58;
  transition: opacity 0.15s ease;
}

.m-msg:active .m-msg__menu,
.m-msg:focus-within .m-msg__menu {
  opacity: 1;
}

.m-msg__text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tg-emoji {
  width: 1.25em;
  height: 1.25em;
  vertical-align: -0.22em;
  object-fit: contain;
}

.tg-emoji--picker {
  width: 1.7rem;
  height: 1.7rem;
  vertical-align: middle;
}

.m-msg__time {
  color: rgba(71, 85, 105, 0.82);
  font-size: 0.64rem;
  line-height: 1;
  margin-top: 0.18rem;
  text-align: right;
  float: right;
  padding-left: 0.55rem;
}

.m-msg__ticks {
  color: currentColor;
  opacity: 0.7;
  font-weight: 800;
}

.m-msg__ticks--read {
  color: var(--m-ios-blue);
  opacity: 1;
}

.m-msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.22rem;
  max-width: min(75%, 25rem);
  margin-top: -0.1rem;
}

.m-msg-row--out .m-msg-reactions {
  justify-content: flex-end;
}

.m-msg-reactions__pill {
  display: inline-flex;
  align-items: center;
  gap: 0.18rem;
  min-height: 1.38rem;
  padding: 0.08rem 0.34rem;
  border: 1px solid rgba(36, 129, 204, 0.16);
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-elevated) 92%, transparent);
  color: var(--m-text);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  font-size: 0.72rem;
  font-weight: 800;
}

.m-msg-reactions__pill--mine {
  border-color: rgba(36, 129, 204, 0.4);
  background: rgba(36, 129, 204, 0.15);
  color: var(--m-ios-blue);
}

.m-msg-reactions__emoji {
  width: 1.05rem;
  height: 1.05rem;
}

html[data-theme="dark"] .m-msg__time {
  color: rgba(226, 232, 240, 0.72);
}

.m-msg img.m-msg__img {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  margin-top: 0.35rem;
}

.m-msg__video {
  display: block;
  width: min(100%, 18rem);
  max-height: 22rem;
  margin-top: 0.35rem;
  border-radius: 12px;
  background: #000;
}

.m-msg__audio {
  min-width: min(16rem, 70vw);
  display: grid;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.m-msg__audio span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--m-muted);
}

.m-msg__audio audio {
  width: 100%;
}

.m-msg__file {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.48rem;
  min-width: min(17rem, 72vw);
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  background: rgba(100, 116, 139, 0.12);
  color: inherit;
  text-decoration: none;
}

.m-msg__file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.m-msg__file-action {
  color: var(--m-ios-blue);
  font-size: 0.75rem;
  font-weight: 800;
}

.m-chat-status {
  flex: 0 0 auto;
  margin: 0 0.65rem 0.35rem;
  padding: 0.45rem 0.65rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  text-align: center;
  font-size: 0.78rem;
}

.m-chat-status--error {
  background: rgba(220, 38, 38, 0.9);
}

.m-chat-status[hidden],
.m-emoji-panel[hidden],
.m-attach-menu[hidden],
.m-compose-context[hidden],
.m-action-sheet[hidden],
.m-composer__mic[hidden],
.m-composer__send[hidden] {
  display: none !important;
}

.m-compose-context {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0.55rem 0.35rem;
  padding: 0.45rem 0.55rem 0.45rem 0.65rem;
  border-left: 3px solid var(--m-ios-blue);
  border-radius: 14px;
  background: color-mix(in srgb, var(--m-elevated) 94%, transparent);
  box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.06);
}

.m-compose-context > div {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 0.04rem;
}

.m-compose-context strong {
  color: var(--m-ios-blue);
  font-size: 0.78rem;
}

.m-compose-context span {
  color: var(--m-muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-compose-context button {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.13);
  color: var(--m-muted);
  font-size: 1.2rem;
}

.m-selection-bar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0.55rem 0.35rem;
  padding: 0.4rem;
  border: 1px solid var(--m-border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--m-elevated) 96%, transparent);
  box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
}

.m-selection-bar[hidden] {
  display: none !important;
}

.m-selection-bar strong {
  min-width: 0;
  color: var(--m-text);
  font-size: 0.86rem;
  text-align: center;
  white-space: nowrap;
}

.m-selection-bar button {
  min-height: 2.3rem;
  border: 0;
  border-radius: 999px;
  padding: 0 0.75rem;
  background: rgba(36, 129, 204, 0.12);
  color: var(--m-ios-blue);
  font-size: 0.8rem;
  font-weight: 800;
}

.m-selection-bar button:disabled {
  opacity: 0.45;
}

.m-selection-bar__cancel {
  background: rgba(100, 116, 139, 0.13) !important;
  color: var(--m-muted) !important;
}

.m-selection-bar__danger {
  background: rgba(220, 38, 38, 0.12) !important;
  color: var(--m-danger) !important;
}

.m-action-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.m-action-sheet * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.m-action-sheet__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(2, 6, 23, 0.46);
}

.m-action-sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 0.55rem;
  max-height: min(78dvh, 34rem);
  overflow: auto;
  padding: 0.5rem max(0.75rem, env(safe-area-inset-right)) calc(0.85rem + var(--m-safe-bottom))
    max(0.75rem, env(safe-area-inset-left));
  border-radius: 26px 26px 0 0;
  background: var(--m-surface);
  box-shadow: 0 -24px 60px rgba(2, 6, 23, 0.28);
  -webkit-overflow-scrolling: touch;
}

.m-action-sheet__handle {
  justify-self: center;
  width: 2.8rem;
  height: 0.3rem;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.32);
}

.m-action-sheet__reactions {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.24rem;
  padding: 0.2rem 0.1rem 0.34rem;
}

.m-action-sheet__reaction {
  min-height: 2.75rem;
  border: 0;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-action-sheet__reaction-emoji {
  width: 1.55rem;
  height: 1.55rem;
}

.m-action-sheet__actions {
  display: grid;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--m-border);
}

.m-action-sheet__action,
.m-forward-list__item {
  min-height: 3.15rem;
  border: 0;
  border-bottom: 1px solid var(--m-border);
  background: color-mix(in srgb, var(--m-elevated) 94%, transparent);
  color: var(--m-text);
  font-weight: 750;
  text-align: left;
  padding: 0 1rem;
}

.m-action-sheet__action:last-child,
.m-forward-list__item:last-child {
  border-bottom: 0;
}

.m-action-sheet__action--danger {
  color: var(--m-danger);
}

.m-message-menu .m-action-sheet__backdrop {
  background: rgba(2, 6, 23, 0.2);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.m-message-menu .m-action-sheet__panel {
  position: absolute;
  left: 10px;
  right: auto;
  top: 10px;
  bottom: auto;
  width: min(260px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  display: grid;
  gap: 0.45rem;
  overflow: auto;
  padding: 0;
  border-radius: 22px;
  background: color-mix(in srgb, var(--m-elevated) 96%, transparent);
  box-shadow: 0 18px 48px rgba(2, 6, 23, 0.24);
  backdrop-filter: blur(24px) saturate(1.24);
  -webkit-backdrop-filter: blur(24px) saturate(1.24);
}

.m-message-menu .m-action-sheet__handle {
  display: none;
}

.m-message-menu .m-action-sheet__reactions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.12rem;
  min-height: 2.7rem;
  padding: 0.22rem;
  border: 1px solid var(--m-border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-elevated) 98%, transparent);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.14);
}

.m-message-menu .m-action-sheet__reaction {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2.25rem;
  border-radius: 999px;
  background: transparent;
}

.m-message-menu .m-action-sheet__reaction:active {
  background: rgba(36, 129, 204, 0.12);
}

.m-message-menu .m-action-sheet__reaction-emoji {
  width: 1.35rem;
  height: 1.35rem;
}

.m-message-menu .m-action-sheet__actions {
  overflow: hidden;
  border: 1px solid var(--m-border);
  border-radius: 20px;
  background: color-mix(in srgb, var(--m-elevated) 96%, transparent);
}

.m-message-menu .m-action-sheet__action {
  min-height: 44px;
  padding: 0 0.95rem;
  background: transparent;
  font-size: 0.94rem;
  font-weight: 700;
}

.m-message-menu .m-action-sheet__action:active {
  background: rgba(36, 129, 204, 0.1);
}

.m-action-sheet__title {
  margin: 0.1rem 0 0;
  font-size: 1rem;
}

.m-forward-list {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--m-border);
  border-radius: 18px;
}

.m-emoji-panel,
.m-attach-menu {
  position: fixed;
  left: max(0.55rem, env(safe-area-inset-left));
  right: max(0.55rem, env(safe-area-inset-right));
  bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift) + 3.1rem);
  z-index: 75;
  flex: 0 0 auto;
  margin: 0;
  border: 1px solid var(--m-border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--m-elevated) 94%, transparent);
  box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
}

.m-emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.12rem;
  max-height: 11.8rem;
  overflow: auto;
  padding: 0.45rem;
  -webkit-overflow-scrolling: touch;
}

.m-emoji-panel__btn,
.m-attach-menu button {
  border: 0;
  background: transparent;
  color: var(--m-text);
  cursor: pointer;
}

.m-emoji-panel__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  border-radius: 12px;
  font-size: 1.35rem;
}

.m-emoji-panel__btn:active,
.m-attach-menu button:active {
  background: rgba(50, 168, 82, 0.1);
}

.m-attach-menu {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.m-attach-menu button {
  min-height: 3rem;
  font-weight: 800;
}

.m-composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift));
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.28rem max(0.5rem, env(safe-area-inset-right)) 0.2rem
    max(0.55rem, env(safe-area-inset-left));
  background: transparent;
  border-top: 0;
}

.m-chat-peers {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.58rem;
  height: calc(var(--m-chat-switcher-h) + var(--m-chat-panel-safe-bottom));
  padding: 6px max(8px, env(safe-area-inset-right)) calc(var(--m-chat-bottom-gap) + var(--m-chat-panel-safe-bottom))
    max(8px, env(safe-area-inset-left));
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: transparent;
}

.m-chat-peers::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.88);
  border-top: 1px solid color-mix(in srgb, var(--m-border) 76%, transparent);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
}

html[data-theme="dark"] .m-chat-peers::before {
  background: rgba(15, 23, 42, 0.88);
}

.m-chat-peers::-webkit-scrollbar {
  display: none;
}

.m-chat-peers > * {
  position: relative;
  z-index: 1;
}

.m-chat-peers__item {
  flex: 0 0 auto;
  width: 3.45rem;
  padding: 2px 0;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--m-muted);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.16rem;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
}

.m-avatar-wrap {
  position: relative;
  flex: 0 0 auto;
}

.m-chat-peer-badge {
  position: absolute;
  top: -0.12rem;
  right: -0.12rem;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #34c759;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.15rem;
  text-align: center;
  box-shadow: 0 0 0 2px var(--m-chat-canvas-mid, var(--m-bg));
  pointer-events: none;
  z-index: 2;
}

.m-chat-peers__item .m-avatar {
  width: 46px;
  height: 46px;
  font-size: 0.82rem;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    outline-color 0.14s ease;
}

.m-chat-peers__item.is-active {
  color: #18884f;
}

.m-chat-peers__item.is-active .m-avatar {
  outline: 3px solid rgba(52, 199, 89, 0.42);
  outline-offset: 2px;
  box-shadow:
    0 0 0 6px rgba(52, 199, 89, 0.12),
    0 8px 18px rgba(24, 136, 79, 0.18);
}

.m-chat-peers__item--general .m-avatar {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent),
    linear-gradient(135deg, #0f7d50, #34c759);
}

.m-chat-peers__item:active .m-avatar {
  transform: scale(0.96);
}

.m-chat-peers__name {
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.m-composer__attach,
.m-composer__emoji,
.m-composer__mic,
.m-composer__send {
  flex: 0 0 auto;
  width: 2.35rem;
  height: 2.35rem;
  border: none;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.m-composer__attach,
.m-composer__emoji,
.m-composer__mic {
  background: rgba(100, 116, 139, 0.13);
  color: var(--m-muted);
}

.m-composer__attach {
  font-size: 1.7rem;
  font-weight: 300;
  line-height: 1;
}

.m-composer__emoji {
  font-size: 1.24rem;
  font-weight: 800;
}

.m-composer__mic.is-recording {
  background: rgba(220, 38, 38, 0.16);
  color: var(--m-danger);
  animation: m-recording-pulse 1s ease-in-out infinite;
}

.m-composer__field {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 2.35rem;
  max-height: 7.5rem;
  padding: 0.48rem 0.88rem;
  border: 1px solid var(--m-border);
  border-radius: 999px;
  font: inherit;
  font-size: 0.98rem;
  line-height: 1.28;
  resize: none;
  background: color-mix(in srgb, var(--m-surface) 90%, transparent);
  color: var(--m-text);
  outline: none;
}

.m-composer__send {
  background: #34c759;
  color: #fff;
  box-shadow: 0 6px 14px rgba(52, 199, 89, 0.24);
}

.m-composer__send:disabled {
  opacity: 0.45;
  cursor: default;
}

@keyframes m-recording-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes m-msg-flash {
  0%,
  100% {
    background: transparent;
  }
  18%,
  72% {
    background: rgba(36, 129, 204, 0.18);
  }
}

/* ----- Premium mobile messenger polish ----- */
.m-header--thread {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  min-height: calc(var(--m-header-h) + var(--m-header-safe-top));
  padding: calc(0.24rem + var(--m-header-safe-top)) max(0.62rem, env(safe-area-inset-right)) 0.36rem
    max(0.62rem, env(safe-area-inset-left));
  gap: 0.38rem;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--m-elevated) 84%, transparent), color-mix(in srgb, var(--m-elevated) 54%, transparent)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--m-border) 58%, transparent);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  z-index: 90;
}

.m-header--thread + .m-main {
  padding-top: calc(var(--m-header-h) + var(--m-header-safe-top));
}

.m-header--thread .m-header__back,
.m-header--thread .m-header__avatar {
  width: 2.18rem;
  min-width: 2.18rem;
  height: 2.18rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: color-mix(in srgb, var(--m-surface) 72%, transparent);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.m-header--thread .m-header__back {
  color: var(--m-ios-blue);
  font-size: 1.28rem;
}

.m-header--thread .m-header__center {
  display: grid;
  align-content: center;
  min-height: 2.18rem;
  max-width: none;
  padding: 0.18rem 0.78rem;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-surface) 66%, transparent);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.07);
  backdrop-filter: blur(18px) saturate(1.22);
  -webkit-backdrop-filter: blur(18px) saturate(1.22);
}

.m-header--thread .m-header__title {
  color: var(--m-text);
  font-size: 0.94rem;
  font-weight: 680;
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.m-header--thread .m-header__subtitle {
  margin-top: 0.02rem;
  color: color-mix(in srgb, var(--m-muted) 86%, transparent);
  font-size: 0.66rem;
  font-weight: 560;
  line-height: 1.05;
}

.m-header--thread .m-header__avatar-img,
.m-avatar img {
  transform: translateZ(0);
  backface-visibility: hidden;
}

.m-thread {
  isolation: isolate;
}

.m-thread__scroll {
  padding: 0.72rem max(0.62rem, env(safe-area-inset-right))
    calc(var(--m-chat-switcher-h) + var(--m-chat-composer-h) + var(--m-chat-compose-lift) + var(--m-chat-panel-safe-bottom) + 1.05rem)
    max(0.62rem, env(safe-area-inset-left));
  gap: 0.42rem;
  scroll-padding-bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-composer-h) + 1rem);
}

.m-thread__virtual-spacer {
  flex: 0 0 auto;
  min-height: 0;
  pointer-events: none;
}

.m-day-separator {
  align-self: center;
  margin: 0.36rem 0 0.2rem;
  padding: 0.24rem 0.66rem;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-elevated) 72%, transparent);
  color: color-mix(in srgb, var(--m-muted) 92%, var(--m-text));
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(16px) saturate(1.16);
  -webkit-backdrop-filter: blur(16px) saturate(1.16);
  font-size: 0.68rem;
  font-weight: 720;
  line-height: 1;
}

.m-unread-separator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.28rem 0;
  color: #15803d;
  font-size: 0.69rem;
  font-weight: 760;
}

.m-unread-separator::before,
.m-unread-separator::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34, 197, 94, 0.44), transparent);
}

.m-unread-separator span {
  flex: 0 0 auto;
  padding: 0.18rem 0.48rem;
  border-radius: 999px;
  background: rgba(236, 253, 245, 0.86);
  box-shadow: 0 6px 16px rgba(22, 163, 74, 0.1);
}

.m-msg-row {
  gap: 0.42rem;
  animation: m-msg-enter 0.22s ease-out both;
  will-change: transform, opacity;
}

.m-msg-row[data-msg-id^="tmp-"] {
  opacity: 0.72;
}

.m-thread__scroll--stable-paint .m-msg-row {
  animation: none;
}

.m-msg-row--grouped-prev {
  margin-top: -0.26rem;
}

.m-msg-row--grouped-prev .m-msg-row__avatar {
  opacity: 0;
}

.m-msg-row__avatar {
  width: 28px;
  height: 28px;
  margin-bottom: 0.08rem;
  border: 1px solid rgba(255, 255, 255, 0.58);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
}

.m-msg {
  max-width: min(78%, 27rem);
  min-width: 2.9rem;
  padding: 0.54rem 0.72rem 0.42rem;
  border-radius: 20px;
  font-size: 0.94rem;
  font-weight: 430;
  line-height: 1.34;
  letter-spacing: -0.01em;
  overflow: hidden;
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.04), 0 7px 18px rgba(15, 23, 42, 0.07);
}

.m-msg--in {
  border-bottom-left-radius: 7px;
  background: color-mix(in srgb, #fff 94%, var(--m-chat-canvas-mid));
  border: 1px solid rgba(255, 255, 255, 0.64);
}

.m-msg--out {
  border-bottom-right-radius: 7px;
  background: linear-gradient(135deg, #e2f8d9 0%, #cef1c2 100%);
  border: 1px solid rgba(22, 163, 74, 0.12);
  color: #0f2b18;
}

.m-msg-row--grouped-prev .m-msg--in {
  border-top-left-radius: 15px;
}

.m-msg-row--grouped-prev .m-msg--out {
  border-top-right-radius: 15px;
}

.m-msg-row--grouped-next .m-msg--in {
  border-bottom-left-radius: 15px;
}

.m-msg-row--grouped-next .m-msg--out {
  border-bottom-right-radius: 15px;
}

.m-msg__who {
  margin: 0 0 0.18rem;
  color: #1687d9;
  font-size: 0.72rem;
  font-weight: 720;
}

.m-msg__text {
  padding-right: 0.18rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}

.m-msg__time {
  float: right;
  margin: 0.22rem 0 0 0.52rem;
  padding-left: 0.28rem;
  color: color-mix(in srgb, var(--m-muted) 72%, transparent);
  font-size: 0.62rem;
  font-weight: 560;
  line-height: 1;
}

.m-msg--out .m-msg__time {
  color: rgba(15, 43, 24, 0.5);
}

.m-msg__menu {
  top: 0.08rem;
  right: 0.08rem;
  width: 1.55rem;
  height: 1.55rem;
  background: color-mix(in srgb, var(--m-elevated) 74%, transparent);
  opacity: 0;
}

.m-msg:active .m-msg__menu,
.m-msg:focus-within .m-msg__menu {
  opacity: 0.78;
}

.m-msg img.m-msg__img,
.m-msg__video {
  width: min(100%, 19rem);
  max-height: 22rem;
  margin: 0.18rem 0 0;
  border-radius: 17px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: rgba(15, 23, 42, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  animation: m-media-reveal 0.24s ease-out both;
}

.m-msg__reply,
.m-msg__forward,
.m-msg__file,
.m-msg__audio {
  border-radius: 15px;
  background: rgba(36, 129, 204, 0.08);
}

.m-msg__audio {
  min-width: min(15.5rem, 68vw);
  padding: 0.56rem;
}

.m-msg__audio span,
.m-msg__file-action {
  font-weight: 720;
}

.m-msg-reactions {
  max-width: min(78%, 27rem);
  margin-top: -0.04rem;
}

.m-msg-reactions__pill {
  min-height: 1.32rem;
  border-color: rgba(255, 255, 255, 0.58);
  background: color-mix(in srgb, var(--m-elevated) 84%, transparent);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.m-thread-skeleton {
  display: grid;
  gap: 0.62rem;
  padding-top: 0.4rem;
}

.m-thread-skeleton__line {
  width: 68%;
  height: 2.75rem;
  border-radius: 20px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.42));
  background-size: 220% 100%;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.07);
  animation: m-skeleton-shimmer 1.15s ease-in-out infinite;
}

.m-thread-skeleton__line--out {
  justify-self: end;
  width: 58%;
  background: linear-gradient(90deg, rgba(209, 250, 229, 0.44), rgba(236, 253, 245, 0.86), rgba(209, 250, 229, 0.44));
  background-size: 220% 100%;
}

.m-thread-skeleton__line--short {
  width: 42%;
}

.m-chat-status {
  position: fixed;
  left: max(0.85rem, env(safe-area-inset-left));
  right: max(0.85rem, env(safe-area-inset-right));
  bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-composer-h) + var(--m-chat-compose-lift) + var(--m-chat-panel-safe-bottom) + 0.5rem);
  z-index: 76;
  margin: 0;
  padding: 0.46rem 0.74rem;
  background: rgba(15, 23, 42, 0.72);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.m-compose-context,
.m-selection-bar {
  position: fixed;
  left: max(0.65rem, env(safe-area-inset-left));
  right: max(0.65rem, env(safe-area-inset-right));
  bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-composer-h) + var(--m-chat-compose-lift) + var(--m-chat-panel-safe-bottom) + 0.35rem);
  z-index: 74;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 18px;
}

.m-emoji-panel,
.m-attach-menu {
  left: max(0.65rem, env(safe-area-inset-left));
  right: max(0.65rem, env(safe-area-inset-right));
  bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-composer-h) + var(--m-chat-compose-lift) + var(--m-chat-panel-safe-bottom) + 0.48rem);
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 24px;
  background: color-mix(in srgb, var(--m-elevated) 86%, transparent);
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.16);
}

.m-emoji-panel {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.18rem;
  max-height: min(16rem, 34dvh);
  padding: 0.62rem;
}

.m-emoji-panel__btn {
  min-height: 2.15rem;
  border-radius: 14px;
}

.m-composer {
  left: max(0.6rem, env(safe-area-inset-left));
  right: max(0.6rem, env(safe-area-inset-right));
  bottom: calc(var(--m-chat-switcher-h) + var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift));
  min-height: var(--m-chat-composer-h);
  padding: 0.36rem;
  gap: 0.34rem;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 28px;
  background: color-mix(in srgb, var(--m-elevated) 88%, transparent);
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.16), 0 2px 0 rgba(255, 255, 255, 0.34) inset;
  backdrop-filter: blur(24px) saturate(1.22);
  -webkit-backdrop-filter: blur(24px) saturate(1.22);
  transform: translateZ(0);
}

.m-composer--sending {
  opacity: 0.86;
}

.m-composer__field {
  min-height: 2.28rem;
  max-height: min(8.5rem, 28dvh);
  padding: 0.5rem 0.58rem;
  border: 0;
  border-radius: 20px;
  background: transparent;
  font-size: 0.96rem;
  line-height: 1.32;
  box-shadow: none;
  transition: height 0.16s ease, background-color 0.16s ease;
}

.m-composer__field::placeholder {
  color: color-mix(in srgb, var(--m-muted) 68%, transparent);
}

.m-composer__field:focus {
  background: rgba(255, 255, 255, 0.18);
}

.m-composer__attach,
.m-composer__emoji,
.m-composer__mic,
.m-composer__send {
  width: 2.28rem;
  height: 2.28rem;
  color: color-mix(in srgb, var(--m-muted) 92%, var(--m-text));
  transition: transform 0.14s ease, background-color 0.14s ease, box-shadow 0.14s ease;
}

.m-composer__attach,
.m-composer__emoji,
.m-composer__mic {
  background: rgba(100, 116, 139, 0.1);
}

.m-composer__send {
  background: linear-gradient(135deg, #34c759, #1f9f4d);
  box-shadow: 0 10px 22px rgba(34, 197, 94, 0.28);
}

.m-composer__attach:active,
.m-composer__emoji:active,
.m-composer__mic:active,
.m-composer__send:active {
  transform: scale(0.94);
}

.m-chat-peers {
  height: calc(var(--m-chat-switcher-h) + var(--m-chat-panel-safe-bottom));
  gap: 0.42rem;
  padding: 0.38rem max(0.58rem, env(safe-area-inset-right)) calc(0.32rem + var(--m-chat-panel-safe-bottom))
    max(0.58rem, env(safe-area-inset-left));
  scroll-snap-type: x proximity;
}

.m-chat-peers::before {
  background: linear-gradient(180deg, color-mix(in srgb, var(--m-elevated) 58%, transparent), color-mix(in srgb, var(--m-elevated) 88%, transparent));
  border-top: 1px solid rgba(255, 255, 255, 0.42);
  box-shadow: 0 -14px 36px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(22px) saturate(1.18);
  -webkit-backdrop-filter: blur(22px) saturate(1.18);
}

.m-chat-peers__item {
  width: 3.05rem;
  min-width: 3.05rem;
  padding: 0.1rem 0;
  gap: 0.08rem;
  border-radius: 16px;
  scroll-snap-align: center;
  font-size: 0.62rem;
  font-weight: 650;
}

.m-chat-peers__item .m-avatar {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  font-size: 0.72rem;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.m-chat-peers__item.is-active {
  color: #0f7d50;
}

.m-chat-peers__item.is-active .m-avatar {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.22), 0 10px 22px rgba(22, 163, 74, 0.18);
}

.m-chat-peers__item.is-active .m-chat-peers__name {
  color: #0f7d50;
}

.m-chat-peers__name {
  max-width: 3rem;
  color: color-mix(in srgb, var(--m-muted) 84%, transparent);
  font-size: 0.61rem;
  line-height: 1.08;
}

.m-chat-peer-badge {
  top: -0.22rem;
  right: -0.24rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  background: linear-gradient(135deg, #34c759, #16a34a);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--m-elevated) 92%, transparent), 0 6px 14px rgba(22, 163, 74, 0.24);
  font-size: 0.56rem;
  line-height: 1rem;
}

body.m-keyboard-open .m-thread::before {
  height: calc(var(--m-chat-composer-h) + var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift));
}

body.m-keyboard-open .m-thread__scroll {
  padding-bottom: calc(var(--m-chat-composer-h) + var(--m-chat-compose-lift) + var(--m-chat-panel-safe-bottom) + var(--m-keyboard-inset) + 1.05rem);
  scroll-padding-bottom: calc(var(--m-chat-composer-h) + var(--m-keyboard-inset) + 1rem);
}

body.m-keyboard-open .m-composer {
  bottom: calc(var(--m-chat-panel-safe-bottom) + var(--m-chat-compose-lift) + var(--m-keyboard-inset));
}

body.m-keyboard-open .m-chat-status,
body.m-keyboard-open .m-compose-context,
body.m-keyboard-open .m-selection-bar,
body.m-keyboard-open .m-emoji-panel,
body.m-keyboard-open .m-attach-menu {
  bottom: calc(var(--m-chat-composer-h) + var(--m-chat-compose-lift) + var(--m-chat-panel-safe-bottom) + var(--m-keyboard-inset) + 0.45rem);
}

body.m-keyboard-open .m-chat-peers {
  pointer-events: none;
  transform: translateY(calc(100% + 12px));
  opacity: 0;
}

html[data-theme="dark"] .m-msg--in {
  background: color-mix(in srgb, #182335 92%, transparent);
  border-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .m-msg--out {
  background: linear-gradient(135deg, #1f6b45 0%, #185936 100%);
  color: #f4fff8;
  border-color: rgba(94, 208, 131, 0.16);
}

html[data-theme="dark"] .m-msg--out .m-msg__time {
  color: rgba(244, 255, 248, 0.54);
}

html[data-theme="dark"] .m-unread-separator span {
  background: rgba(22, 101, 52, 0.72);
  color: #bbf7d0;
}

html[data-theme="dark"] .m-thread-skeleton__line {
  background: linear-gradient(90deg, rgba(30, 41, 59, 0.52), rgba(51, 65, 85, 0.78), rgba(30, 41, 59, 0.52));
  background-size: 220% 100%;
}

@keyframes m-msg-enter {
  from {
    opacity: 0;
    transform: translate3d(0, 7px, 0) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes m-media-reveal {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes m-skeleton-shimmer {
  0% {
    background-position: 120% 0;
  }
  100% {
    background-position: -120% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .m-msg-row,
  .m-msg img.m-msg__img,
  .m-msg__video,
  .m-thread-skeleton__line {
    animation: none;
  }
}

/* ----- Clients / Contracts ----- */
.m-sec-title {
  margin: 0.85rem 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--m-muted);
}

.m-client-row,
.m-contract-row {
  width: 100%;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: var(--m-surface);
  margin-bottom: 0.45rem;
  overflow: hidden;
}

.m-client-row summary,
.m-contract-row summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  min-height: calc(var(--m-touch) + 4px);
  touch-action: manipulation;
}

.m-client-row summary::-webkit-details-marker,
.m-contract-row summary::-webkit-details-marker {
  display: none;
}

.m-client-row__name,
.m-contract-row__name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
}

.m-client-row__body,
.m-contract-row__body {
  padding: 0 0.85rem 0.85rem;
  font-size: 0.85rem;
  color: var(--m-muted);
  line-height: 1.45;
}

.m-contract-row__body p {
  margin: 0 0 0.35rem;
}

.m-contract-row__body p:last-child {
  margin-bottom: 0;
}

.m-contract-row__archive {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.18rem 0.42rem;
  background: rgba(100, 116, 139, 0.12);
  color: var(--m-muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.m-contract-list {
  display: grid;
  align-content: start;
  gap: 0.45rem;
}

.m-contract-list__search {
  display: grid;
  gap: 0.35rem;
  padding: 0.72rem 0.75rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: color-mix(in srgb, var(--m-elevated) 92%, transparent);
}

.m-contract-list__status-filter {
  display: grid;
  gap: 0.35rem;
  padding: 0.72rem 0.75rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: color-mix(in srgb, var(--m-elevated) 92%, transparent);
}

.m-contract-list__search span,
.m-contract-list__status-filter span {
  color: var(--m-muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.m-contract-list__search input,
.m-contract-list__status-filter select {
  width: 100%;
  min-height: var(--m-touch);
  border: 1px solid var(--m-border);
  border-radius: 0.9rem;
  padding: 0.65rem 0.78rem;
  background: var(--m-surface);
  color: var(--m-text);
  font: inherit;
  outline: none;
}

.m-contract-list__search input:focus,
.m-contract-list__status-filter select:focus {
  border-color: color-mix(in srgb, var(--m-accent) 68%, var(--m-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--m-accent) 16%, transparent);
}

.m-contract-list__filter {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: var(--m-touch);
  padding: 0.58rem 0.75rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: color-mix(in srgb, var(--m-elevated) 92%, transparent);
  color: var(--m-text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
}

.m-contract-list__filter input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--m-accent);
}

.m-contract-list__items {
  display: grid;
  gap: 0.45rem;
}

.m-contract-list__item {
  width: 100%;
  min-height: calc(var(--m-touch) + 2px);
  display: grid;
  align-items: start;
  gap: 0.55rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  padding: 0.72rem 0.85rem;
  background: var(--m-surface);
  color: var(--m-text);
  text-align: left;
  font: inherit;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
}

.m-contract-list__head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.m-contract-list__item--pending {
  border-color: rgba(220, 38, 38, 0.42);
  background: color-mix(in srgb, rgba(220, 38, 38, 0.12) 70%, var(--m-surface));
  box-shadow:
    0 0 0 1px rgba(220, 38, 38, 0.08),
    0 8px 22px rgba(220, 38, 38, 0.12);
}

.m-contract-list__item--pending .m-contract-list__number {
  color: #b91c1c;
}

html[data-theme="dark"] .m-contract-list__item--pending .m-contract-list__number {
  color: #fca5a5;
}

.m-contract-list__number {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.98rem;
  font-weight: 750;
}

.m-contract-list__meta {
  display: grid;
  gap: 0.42rem;
  min-width: 0;
}

.m-contract-list__row {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
}

.m-contract-list__row em {
  color: var(--m-muted);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.m-contract-list__row b {
  min-width: 0;
  color: var(--m-text);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.28;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-contract-list__row--address b,
.m-contract-list__row--comment b {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  white-space: normal;
}

.m-contract-list__row--address b {
  -webkit-line-clamp: 2;
}

.m-contract-list__row--comment b {
  -webkit-line-clamp: 3;
}

.m-contract-list__dates {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
}

.m-contract-list__row--total {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.5rem;
  padding-top: 0.1rem;
}

.m-contract-list__row--total b {
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
}

.m-contract-list__status {
  flex: 0 1 auto;
  max-width: 48%;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 700;
}

.m-contract-list__status--draft {
  background: rgba(100, 116, 139, 0.14);
  color: var(--m-muted);
}

.m-contract-list__status--ready {
  background: rgba(74, 143, 111, 0.15);
  color: var(--m-accent);
}

.m-contract-list__status--pending-agreement {
  background: rgba(217, 119, 6, 0.14);
  color: #b45309;
}

.m-contract-list__status--rejected-agreement {
  background: rgba(220, 38, 38, 0.14);
  color: #b91c1c;
}

.m-contract-list__status--agreed {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
}

.m-contract-list__status--signed-ready {
  background: rgba(234, 179, 8, 0.18);
  color: #a16207;
}

.m-contract-list__status--in-transit {
  background: rgba(6, 182, 212, 0.14);
  color: #0e7490;
}

.m-contract-list__status--paid-unloaded {
  background: rgba(22, 163, 74, 0.14);
  color: #15803d;
}

.m-contract-list__status--paid-not-unloaded {
  background: linear-gradient(
    90deg,
    rgba(22, 163, 74, 0.22) 0%,
    rgba(22, 163, 74, 0.22) 50%,
    rgba(220, 38, 38, 0.2) 50%,
    rgba(220, 38, 38, 0.2) 100%
  );
  color: #1f2937;
}

.m-contract-list__status--unloaded-not-paid {
  background: rgba(220, 38, 38, 0.16);
  color: #b91c1c;
}

.m-contract-list__status--return {
  background: rgba(107, 114, 128, 0.16);
  color: #4b5563;
}

html[data-theme="dark"] .m-contract-list__status--paid-not-unloaded {
  color: #f8fafc;
}

/* ----- Mobile ATI requests ----- */
.m-requests {
  display: grid;
  align-content: start;
  gap: 0.72rem;
  padding-top: 0.35rem;
  padding-bottom: calc(1rem + var(--m-nav-h) + var(--m-safe-bottom));
  scroll-padding-bottom: calc(1rem + var(--m-nav-h) + var(--m-safe-bottom));
}

.m-requests__hero {
  padding: 1rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background:
    radial-gradient(circle at 90% 0%, rgba(50, 168, 82, 0.18), transparent 34%),
    var(--m-surface);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.m-requests__hero h2 {
  margin: 0 0 0.35rem;
  font-size: 1.12rem;
  letter-spacing: -0.03em;
}

.m-requests__hero p {
  margin: 0;
  color: var(--m-muted);
  font-size: 0.84rem;
  line-height: 1.42;
}

.m-requests__eyebrow {
  margin: 0 0 0.18rem !important;
  color: var(--m-accent) !important;
  font-size: 0.7rem !important;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.m-requests__actions,
.m-requests__sheet-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
}

.m-requests__action {
  min-height: 2.9rem;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #32a852, #258b43);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 850;
  box-shadow: 0 10px 20px rgba(37, 139, 67, 0.22);
}

.m-requests__action--ghost {
  background: var(--m-surface);
  color: var(--m-text);
  border: 1px solid var(--m-border);
  box-shadow: none;
}

.m-requests__action:disabled {
  opacity: 0.48;
  box-shadow: none;
}

.m-requests__switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0.22rem;
  border: 1px solid var(--m-border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--m-surface) 78%, transparent);
}

.m-requests__switch button {
  min-height: 2.25rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--m-muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
}

.m-requests__switch button.is-active {
  background: var(--m-accent-soft);
  color: var(--m-accent);
}

.m-requests__switch span {
  margin-left: 0.25rem;
  font-size: 0.72rem;
}

.m-requests__list {
  display: grid;
  gap: 0.5rem;
}

.m-requests__card {
  width: 100%;
  display: grid;
  gap: 0.4rem;
  padding: 0.82rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: var(--m-surface);
  color: var(--m-text);
  text-align: left;
  font: inherit;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

.m-requests__card--selected {
  border-color: color-mix(in srgb, var(--m-accent) 70%, var(--m-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--m-accent-soft) 72%, transparent);
}

.m-requests__card-top,
.m-requests__foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
}

.m-requests__card-top strong {
  min-width: 0;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.m-requests__badge {
  flex: 0 0 auto;
  max-width: 48%;
  padding: 0.18rem 0.44rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.14);
  color: #15803d;
  font-size: 0.68rem;
  font-weight: 850;
}

.m-requests__badge--archived {
  background: rgba(100, 116, 139, 0.14);
  color: var(--m-muted);
}

.m-requests__line {
  color: var(--m-text);
  font-size: 0.84rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.m-requests__meta,
.m-requests__foot {
  color: var(--m-muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.m-requests__foot span:first-child {
  color: var(--m-accent);
  font-weight: 850;
}

.m-requests .m-contract-driver-sheet {
  inset: 0 0 calc(var(--m-nav-h) + var(--m-safe-bottom)) 0;
  z-index: 120;
}

.m-requests .m-contract-driver-sheet__panel {
  max-height: calc(100dvh - var(--m-header-h) - var(--m-nav-h) - var(--m-safe-top) - var(--m-safe-bottom) - 0.9rem);
  padding-top: 0.5rem;
  padding-bottom: 1.2rem;
  scroll-padding-bottom: 1.4rem;
  overscroll-behavior: contain;
}

.m-requests .m-contract-driver-sheet__handle {
  margin-bottom: 0.45rem;
}

.m-requests .m-contract-driver-sheet__head {
  margin-bottom: 0.45rem;
}

.m-requests .m-contract-driver-sheet__hint {
  margin-bottom: 0.65rem;
}

.m-requests .m-requests__sheet-actions {
  padding-bottom: 0.25rem;
}

.m-requests .m-contract-driver-sheet__publish {
  margin-bottom: 0.1rem;
}

.m-delivery-form {
  gap: 0.72rem;
}

.m-delivery-form__summary {
  margin-bottom: 0.1rem;
  padding: 0.72rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  background: rgba(248, 250, 252, 0.88);
}

html[data-theme="dark"] .m-delivery-form__summary {
  border-color: rgba(226, 232, 240, 0.1);
  background: rgba(15, 23, 42, 0.78);
}

.m-delivery-form__summary dl {
  display: grid;
  gap: 0.45rem;
  margin: 0;
}

.m-delivery-form__summary div {
  display: grid;
  grid-template-columns: 6.4rem minmax(0, 1fr);
  gap: 0.55rem;
}

.m-delivery-form__summary dt,
.m-delivery-form__summary dd {
  margin: 0;
  min-width: 0;
  font-size: 0.76rem;
  line-height: 1.35;
}

.m-delivery-form__summary dt {
  color: #64748b;
  font-weight: 850;
}

.m-delivery-form__summary dd {
  color: #0f172a;
  overflow-wrap: anywhere;
}

html[data-theme="dark"] .m-delivery-form__summary dt {
  color: #94a3b8;
}

html[data-theme="dark"] .m-delivery-form__summary dd {
  color: #f8fafc;
}

.m-delivery-form__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.58rem;
}

.m-delivery-download {
  display: grid;
  gap: 0.35rem;
  margin: 0 0 0.7rem;
  padding: 0.72rem;
  border: 1px solid rgba(22, 163, 74, 0.24);
  border-radius: 14px;
  background: rgba(34, 197, 94, 0.1);
  color: #14532d;
}

.m-delivery-download[hidden] {
  display: none !important;
}

.m-delivery-download strong {
  font-size: 0.9rem;
}

.m-delivery-download span {
  font-size: 0.78rem;
  line-height: 1.35;
}

.m-delivery-download button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  margin-top: 0.2rem;
  border: none;
  border-radius: 12px;
  background: #16a34a;
  color: #fff;
  font: inherit;
  font-weight: 850;
}

.m-delivery-download button:disabled {
  opacity: 0.72;
}

html[data-theme="dark"] .m-delivery-download {
  background: rgba(34, 197, 94, 0.15);
  color: #bbf7d0;
}

@media (max-width: 360px) {
  .m-delivery-form__grid,
  .m-contract-summary__delivery-grid,
  .m-delivery-form__summary div {
    grid-template-columns: 1fr;
  }
}

.m-contract-detail__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.m-contract-actions {
  position: sticky;
  top: 0.4rem;
  z-index: 2;
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: color-mix(in srgb, var(--m-elevated) 94%, transparent);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

.m-contract-viewer {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #eef2f7;
  color: #111827;
}

.m-contract-viewer__bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.65rem;
  padding: calc(0.42rem + var(--m-safe-top)) max(0.65rem, env(safe-area-inset-right)) 0.52rem
    max(0.65rem, env(safe-area-inset-left));
  background: rgba(17, 24, 39, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.m-contract-viewer__bar strong,
.m-contract-viewer__bar span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-contract-viewer__bar strong {
  color: #fff;
  font-size: 0.92rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.m-contract-viewer__bar span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.74rem;
}

.m-contract-viewer__back,
.m-contract-viewer__approve,
.m-contract-viewer__simple,
.m-contract-viewer__driver {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
}

.m-contract-viewer__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.42rem;
  min-width: 0;
}

.m-contract-viewer__back {
  width: 2.55rem;
  height: 2.55rem;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.25rem;
}

.m-contract-viewer__approve {
  display: inline-flex;
  width: 2.55rem;
  height: 2.55rem;
  align-items: center;
  justify-content: center;
  background: #22c55e;
  color: #fff;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.28);
}

.m-contract-viewer__approve:disabled {
  opacity: 0.66;
}

.m-contract-viewer__approve svg {
  display: block;
}

.m-contract-viewer__simple {
  display: inline-flex;
  width: 2.55rem;
  height: 2.55rem;
  align-items: center;
  justify-content: center;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.22);
}

.m-contract-viewer__simple:active {
  transform: translateY(1px);
}

.m-contract-viewer__driver {
  display: inline-flex;
  width: 2.55rem;
  height: 2.55rem;
  align-items: center;
  justify-content: center;
  background: #f97316;
  color: #fff;
  box-shadow: 0 8px 20px rgba(249, 115, 22, 0.28);
}

.m-contract-viewer__driver:active {
  transform: translateY(1px);
}

.m-contract-viewer__body {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 0.8rem max(0.75rem, env(safe-area-inset-right)) calc(0.9rem + var(--m-safe-bottom))
    max(0.75rem, env(safe-area-inset-left));
  -webkit-overflow-scrolling: touch;
}

.m-contract-viewer__body--modal-open {
  overflow: hidden;
}

.m-contract-driver-sheet[hidden] {
  display: none !important;
}

.m-contract-summary__actions {
  display: grid;
  gap: 0.55rem;
}

.m-contract-summary__action-button {
  width: 100%;
  min-height: 2.65rem;
  border: 1px solid var(--m-border);
  border-radius: 16px;
  background: var(--m-surface);
  color: var(--m-text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 900;
}

.m-contract-summary__action-button.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  cursor: wait;
}

.m-contract-summary__action-button.is-loading::before {
  content: "";
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: m-contract-btn-spin 0.75s linear infinite;
}

@keyframes m-contract-btn-spin {
  to {
    transform: rotate(360deg);
  }
}

.m-contract-summary__action-button--primary {
  border-color: transparent;
  background: var(--m-accent);
  color: #fff;
}

.m-contract-summary__action-button--danger {
  border-color: rgba(185, 28, 28, 0.2);
  background: #fee2e2;
  color: #b91c1c;
}

.m-contract-summary__action-button:active {
  transform: translateY(1px);
}

.m-contract-summary__action-button:disabled {
  opacity: 0.68;
}

.m-contract-edit-sheet[hidden] {
  display: none !important;
}

.m-contract-edit-sheet {
  position: fixed;
  inset: 0;
  z-index: 94;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.m-contract-edit-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.58);
}

.m-contract-edit-sheet__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 36rem;
  max-height: calc(100vh - 1.2rem - var(--m-safe-top));
  overflow: auto;
  padding: 0.62rem max(0.88rem, env(safe-area-inset-right)) calc(0.9rem + var(--m-safe-bottom))
    max(0.88rem, env(safe-area-inset-left));
  border-radius: 24px 24px 0 0;
  background: #fff;
  box-shadow: 0 -18px 48px rgba(15, 23, 42, 0.28);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.m-contract-edit-sheet__handle {
  width: 2.8rem;
  height: 0.28rem;
  margin: 0 auto 0.72rem;
  border-radius: 999px;
  background: #cbd5e1;
}

.m-contract-edit-sheet__head,
.m-contract-edit-sheet__section-head,
.m-contract-edit-item__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.m-contract-edit-sheet__head {
  margin-bottom: 0.65rem;
}

.m-contract-edit-sheet__head span {
  display: block;
  margin-bottom: 0.12rem;
  color: var(--m-accent);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.m-contract-edit-sheet__head strong {
  display: block;
  color: #0f172a;
  font-size: 1.08rem;
}

.m-contract-edit-sheet__close {
  flex: 0 0 auto;
  width: 2.35rem;
  height: 2.35rem;
  border: 0;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
  font: inherit;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
}

.m-contract-edit-sheet__section {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e2e8f0;
}

.m-contract-edit-sheet__section h3 {
  margin: 0 0 0.65rem;
  color: #0f172a;
  font-size: 0.98rem;
}

.m-contract-edit-sheet__section-head button,
.m-contract-edit-item__head button {
  border: 0;
  border-radius: 999px;
  padding: 0.38rem 0.65rem;
  background: #eef6f1;
  color: var(--m-accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 900;
}

.m-contract-edit-item__head button {
  background: #fee2e2;
  color: #b91c1c;
}

.m-contract-edit-sheet__field {
  display: grid;
  gap: 0.34rem;
  margin-bottom: 0.66rem;
}

.m-contract-edit-sheet__field span {
  color: #334155;
  font-size: 0.78rem;
  font-weight: 900;
}

.m-contract-edit-sheet__field input,
.m-contract-edit-sheet__field textarea,
.m-contract-edit-sheet__field select,
.m-contract-edit-sheet__pick-product {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 15px;
  padding: 0.74rem 0.82rem;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-size: 0.96rem;
  font-weight: 750;
  outline: none;
}

.m-contract-edit-sheet__pick-product {
  min-height: 2.8rem;
  text-align: left;
  white-space: normal;
}

.m-contract-edit-sheet__field textarea {
  resize: vertical;
  line-height: 1.35;
}

.m-contract-edit-sheet__field select {
  appearance: none;
  -webkit-appearance: none;
}

.m-contract-edit-sheet__note {
  margin: -0.25rem 0 0.7rem;
  color: #64748b;
  font-size: 0.78rem;
  line-height: 1.35;
}

.m-contract-edit-sheet__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.8rem minmax(0, 1fr);
  gap: 0.45rem;
}

.m-contract-edit-item {
  margin-bottom: 0.65rem;
  padding: 0.7rem;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  background: #f8fafc;
}

.m-contract-edit-item__head {
  align-items: center;
  margin-bottom: 0.55rem;
}

.m-contract-edit-item__head strong {
  color: #0f172a;
  font-size: 0.92rem;
}

.m-contract-edit-sheet__empty {
  margin: 0;
  color: #64748b;
  font-size: 0.86rem;
}

.m-contract-edit-sheet__error {
  margin: 0.75rem 0 0;
  color: #b91c1c;
  font-size: 0.86rem;
  font-weight: 800;
}

.m-contract-edit-sheet__save {
  width: 100%;
  min-height: 3rem;
  margin-top: 0.85rem;
  border: 0;
  border-radius: 18px;
  background: var(--m-accent);
  color: #fff;
  font: inherit;
  font-size: 0.96rem;
  font-weight: 900;
  touch-action: pan-y;
}

.m-contract-edit-sheet__save:disabled {
  opacity: 0.65;
}

.m-contract-edit-sheet__cancel {
  width: 100%;
  min-height: 2.8rem;
  margin-top: 0.55rem;
  border: 0;
  border-radius: 18px;
  background: #e2e8f0;
  color: #0f172a;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 900;
  touch-action: pan-y;
}

.m-contract-driver-sheet {
  position: fixed;
  inset: 0;
  z-index: 92;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.m-contract-driver-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.58);
}

.m-contract-driver-sheet__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 34rem;
  max-height: calc(100vh - 1.2rem - var(--m-safe-top));
  overflow: auto;
  padding: 0.62rem max(0.88rem, env(safe-area-inset-right)) calc(0.9rem + var(--m-safe-bottom))
    max(0.88rem, env(safe-area-inset-left));
  border-radius: 24px 24px 0 0;
  background: #fff;
  box-shadow: 0 -18px 48px rgba(15, 23, 42, 0.28);
  -webkit-overflow-scrolling: touch;
}

.m-contract-driver-sheet__handle {
  width: 2.8rem;
  height: 0.28rem;
  margin: 0 auto 0.72rem;
  border-radius: 999px;
  background: #cbd5e1;
}

.m-contract-driver-sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.55rem;
}

.m-contract-driver-sheet__head span {
  display: block;
  margin-bottom: 0.12rem;
  color: #f97316;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.m-contract-driver-sheet__head strong {
  display: block;
  color: #0f172a;
  font-size: 1.08rem;
}

.m-contract-driver-sheet__close {
  flex: 0 0 auto;
  width: 2.35rem;
  height: 2.35rem;
  border: 0;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
  font: inherit;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
}

.m-contract-driver-sheet__hint {
  margin: 0 0 0.85rem;
  color: #64748b;
  font-size: 0.86rem;
  line-height: 1.38;
}

.m-contract-driver-sheet__field {
  display: grid;
  gap: 0.38rem;
  margin-bottom: 0.72rem;
}

.m-contract-driver-sheet__field span {
  color: #334155;
  font-size: 0.8rem;
  font-weight: 900;
}

.m-contract-driver-sheet__field input,
.m-contract-driver-sheet__field textarea,
.m-contract-driver-sheet__field select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  padding: 0.82rem 0.9rem;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  outline: none;
}

.m-contract-driver-sheet__field textarea {
  min-height: 5rem;
  resize: vertical;
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.35;
}

.m-contract-driver-sheet__field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;
  background-image: linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position:
    calc(100% - 1.2rem) 50%,
    calc(100% - 0.84rem) 50%;
  background-size: 0.36rem 0.36rem, 0.36rem 0.36rem;
  background-repeat: no-repeat;
  font-size: 0.9rem;
  font-weight: 750;
  line-height: 1.25;
}

.m-contract-driver-sheet__field input:focus,
.m-contract-driver-sheet__field textarea:focus,
.m-contract-driver-sheet__field select:focus {
  border-color: #f97316;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.16);
}

.m-contract-driver-sheet__date-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5.1rem;
  gap: 0.44rem;
  align-items: start;
}

.m-contract-driver-sheet__date-row .m-contract-driver-sheet__field input {
  padding-left: 0.58rem;
  padding-right: 0.58rem;
  font-size: 0.88rem;
}

.m-contract-driver-sheet__date-row .m-contract-driver-sheet__field:last-child input {
  text-align: center;
}

.m-contract-driver-sheet__details {
  margin: 0 0 0.74rem;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #f8fafc;
}

.m-contract-driver-sheet__details summary {
  padding: 0.72rem 0.8rem;
  color: #334155;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 900;
  list-style: none;
}

.m-contract-driver-sheet__details summary::-webkit-details-marker {
  display: none;
}

.m-contract-driver-sheet__details summary::after {
  content: "Показать";
  float: right;
  color: #f97316;
  font-size: 0.74rem;
}

.m-contract-driver-sheet__details[open] summary::after {
  content: "Скрыть";
  color: #64748b;
}

.m-contract-driver-sheet__details dl {
  display: grid;
  gap: 0.48rem;
  margin: 0;
  padding: 0 0.8rem 0.82rem;
}

.m-contract-driver-sheet__detail-row {
  display: grid;
  grid-template-columns: 6.9rem minmax(0, 1fr);
  gap: 0.55rem;
  align-items: start;
}

.m-contract-driver-sheet__detail-row dt,
.m-contract-driver-sheet__detail-row dd {
  margin: 0;
  min-width: 0;
  font-size: 0.76rem;
  line-height: 1.32;
}

.m-contract-driver-sheet__detail-row dt {
  color: #64748b;
  font-weight: 850;
}

.m-contract-driver-sheet__detail-row dd {
  color: #0f172a;
  overflow-wrap: anywhere;
}

.m-contract-driver-sheet__error {
  margin: 0 0 0.75rem;
  padding: 0.62rem 0.7rem;
  border-radius: 14px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 0.8rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.m-contract-driver-sheet__publish {
  width: 100%;
  min-height: 3rem;
  border: 0;
  border-radius: 18px;
  background: #f97316;
  color: #fff;
  font: inherit;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(249, 115, 22, 0.24);
}

.m-contract-driver-sheet__publish:disabled {
  opacity: 0.72;
  box-shadow: none;
}

.m-contract-driver-sheet__copy-status {
  margin: -0.2rem 0 0.72rem;
  color: #15803d;
  font-size: 0.86rem;
  font-weight: 850;
}

.m-contract-simple-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
}

.m-contract-simple-actions button {
  min-height: 2.8rem;
  border: 0;
  border-radius: 15px;
  background: #f97316;
  color: #fff;
  font: inherit;
  font-weight: 900;
}

.m-contract-simple-actions button:last-child {
  background: #e2e8f0;
  color: #0f172a;
}

.m-contract-pdf-export-host {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 194mm;
  min-height: 0;
  background: #fff;
  pointer-events: none;
  z-index: -1;
}

.m-contract-pdf-export-host .m-contract-full-doc {
  width: 194mm;
  max-width: none;
  min-height: 0;
  margin: 0;
  box-sizing: border-box;
  box-shadow: none;
}

.m-contract-pdf-capture-wrap {
  margin: 0;
  box-sizing: border-box;
}

.m-contract-full-doc--pdf-dense {
  padding-top: 24px;
  padding-bottom: 24px;
}

.m-contract-full-doc--pdf-dense h1 {
  margin: 7px 0 9px;
  font-size: 17px;
}

.m-contract-full-doc--pdf-dense .m-contract-full-doc__line {
  margin-bottom: 6px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.m-contract-full-doc--pdf-dense .m-contract-full-doc__table {
  margin-top: 8px;
  font-size: 11px;
}

.m-contract-full-doc--pdf-dense .m-contract-full-doc__table th,
.m-contract-full-doc--pdf-dense .m-contract-full-doc__table td {
  padding: 4px 6px;
}

.m-contract-full-doc--pdf-dense .m-contract-full-doc__terms {
  margin: 12px 0;
  padding: 8px 10px;
  font-size: 10.5px;
}

.m-contract-full-doc--pdf-dense .m-contract-full-doc__footer {
  margin-top: 10px;
  gap: 12px;
}

.m-contract-full-doc--pdf-dense .m-contract-full-doc__footer section {
  min-height: 180px;
  padding: 10px;
}

.m-contract-viewer__comment {
  flex: 0 0 auto;
  padding: 0.56rem max(0.75rem, env(safe-area-inset-right)) 0.6rem max(0.75rem, env(safe-area-inset-left));
  background: rgba(52, 199, 89, 0.14);
  border-bottom: 1px solid rgba(52, 199, 89, 0.2);
}

.m-contract-viewer__comment strong {
  display: block;
  color: #86efac;
  font-size: 0.74rem;
  margin-bottom: 0.16rem;
}

.m-contract-viewer__comment p {
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.84rem;
  line-height: 1.34;
}

.m-contract-agreement-photos {
  flex: 0 0 auto;
  margin-top: 0.75rem;
  padding: 0.7rem;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.m-contract-agreement-photos__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
}

.m-contract-agreement-photos__head strong {
  color: #2563eb;
  font-size: 0.74rem;
}

.m-contract-agreement-photos__hint {
  margin: 0 0 0.45rem;
  color: #64748b;
  font-size: 0.78rem;
  line-height: 1.35;
}

.m-contract-agreement-photos__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.m-contract-agreement-photos__link {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font: inherit;
}

.m-contract-agreement-photos__thumb {
  display: block;
  width: 4.75rem;
  height: 4.75rem;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(147, 197, 253, 0.45);
}

.m-contract-agreement-photos__add {
  flex: 0 0 auto;
  font-size: 0.78rem;
  padding: 0.32rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.28);
  background: #eff6ff;
  color: #1d4ed8;
}

.m-contract-viewer__canvas {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem max(0.55rem, env(safe-area-inset-right)) calc(0.55rem + var(--m-safe-bottom))
    max(0.85rem, env(safe-area-inset-left));
}

.m-contract-summary {
  display: grid;
  gap: 0.65rem;
}

.m-contract-summary__hero,
.m-contract-summary__section,
.m-contract-summary__buyer {
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.m-contract-summary__hero {
  padding: 0.85rem;
  background: linear-gradient(135deg, #ffffff 0%, #ecfdf5 100%);
}

.m-contract-summary__eyebrow {
  display: block;
  margin-bottom: 0.24rem;
  color: #0f7d50;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.m-contract-summary__hero h1 {
  margin: 0 0 0.7rem;
  color: #0f172a;
  font-size: 1rem;
  line-height: 1.22;
}

.m-contract-summary__total {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.7rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(15, 125, 80, 0.16);
}

.m-contract-summary__total span,
.m-contract-summary__section-head span,
.m-contract-summary__tax span,
.m-contract-summary__kv dt {
  color: #64748b;
  font-size: 0.76rem;
  font-weight: 800;
}

.m-contract-summary__total strong {
  color: #0f7d50;
  font-size: 1.26rem;
  line-height: 1;
  white-space: nowrap;
}

.m-contract-summary__total--below-tax {
  margin-top: 0.55rem;
}

.m-contract-summary__section {
  padding: 0.78rem;
}

.m-contract-summary__section h2,
.m-contract-summary__section-head h2 {
  margin: 0;
  color: #0f172a;
  font-size: 0.9rem;
  line-height: 1.25;
}

.m-contract-summary__section > h2 {
  margin-bottom: 0.45rem;
}

.m-contract-summary__section > .m-contract-summary__text + h2 {
  margin-top: 0.85rem;
}

.m-contract-summary__section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
}

.m-contract-summary__items {
  display: grid;
  gap: 0.48rem;
}

.m-contract-summary-item {
  display: grid;
  gap: 0.52rem;
  padding: 0.68rem;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
}

.m-contract-summary-item strong {
  color: #111827;
  font-size: 0.92rem;
  line-height: 1.3;
}

.m-contract-summary-item__meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.42rem;
  align-items: center;
}

.m-contract-summary-item__meta span {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
  padding: 0.4rem 0.45rem;
  border-radius: 12px;
  background: #fff;
}

.m-contract-summary-item__meta em {
  color: #64748b;
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 800;
}

.m-contract-summary-item__meta b {
  color: #0f172a;
  font-size: 0.9rem;
  line-height: 1.12;
  white-space: nowrap;
}

.m-contract-summary__tax {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid #e2e8f0;
}

.m-contract-summary__tax strong {
  color: #0f172a;
  font-size: 0.86rem;
  white-space: nowrap;
}

.m-contract-summary__text,
.m-contract-summary__empty {
  margin: 0;
  color: #334155;
  font-size: 0.86rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.m-contract-summary__comment-button {
  display: grid;
  gap: 0.45rem;
  width: 100%;
  padding: 0.65rem 0.7rem;
  border: 1px solid rgba(15, 125, 80, 0.18);
  border-radius: 14px;
  background: #f8fafc;
  color: inherit;
  font: inherit;
  text-align: left;
}

.m-contract-summary__comment-button span {
  color: #334155;
  font-size: 0.86rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.m-contract-summary__comment-button b {
  justify-self: start;
  border-radius: 999px;
  background: #ecfdf5;
  color: #0f7d50;
  font-size: 0.74rem;
  font-weight: 900;
  padding: 0.26rem 0.56rem;
}

.m-contract-summary__status {
  display: grid;
  gap: 0.5rem;
}

.m-contract-summary__status-select {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  background: #fff;
  color: #0f172a;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 800;
  padding: 0 0.75rem;
}

.m-contract-summary__status-select:disabled {
  opacity: 0.7;
}

.m-contract-summary__delivery {
  gap: 0.58rem;
}

.m-contract-summary__delivery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 0.52rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.m-contract-summary__delivery-grid[hidden] {
  display: none !important;
}

.m-contract-summary__delivery-field {
  display: grid;
  grid-template-rows: 2.1rem 2.75rem;
  gap: 0.34rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.m-contract-summary__delivery-field span {
  display: flex;
  align-items: flex-end;
  color: #475569;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.15;
}

.m-contract-summary__delivery-field input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  inline-size: 100%;
  max-width: 100%;
  max-inline-size: 100%;
  min-width: 0;
  min-inline-size: 0;
  height: 2.75rem;
  min-height: 2.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  background: #fff;
  color: #0f172a;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  padding: 0 0.75rem;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-contract-summary__delivery-field input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
  font-size: 0.82rem;
  line-height: 1;
}

.m-contract-summary__delivery-field input[type="date"]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: left;
}

.m-contract-summary__status-select:focus,
.m-contract-summary__delivery-field input:focus {
  border-color: #0f7d50;
  box-shadow: 0 0 0 3px rgba(15, 125, 80, 0.14);
}

.m-contract-summary__status-save {
  width: 100%;
  min-height: 2.85rem;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #0f7d50, #14945f);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(15, 125, 80, 0.18);
}

.m-contract-summary__status-save:disabled,
.m-contract-summary__delivery-field input:disabled {
  opacity: 0.7;
  box-shadow: none;
}

.m-contract-summary__status-note {
  margin: 0;
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 700;
}

.m-contract-summary__signed-copy {
  display: grid;
  gap: 0.55rem;
}

.m-contract-summary__buyer {
  overflow: hidden;
}

.m-contract-summary__buyer h2 {
  margin: 0;
  padding: 0.78rem 0.8rem 0.55rem;
  color: #0f172a;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1.25;
}

.m-contract-summary__buyer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem;
  cursor: pointer;
  list-style: none;
}

.m-contract-summary__buyer summary::-webkit-details-marker {
  display: none;
}

.m-contract-summary__buyer summary span {
  color: #0f172a;
  font-size: 0.9rem;
  font-weight: 900;
}

.m-contract-summary__buyer summary b {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.26rem 0.55rem;
  background: #ecfdf5;
  color: #0f7d50;
  font-size: 0.72rem;
}

.m-contract-summary__buyer[open] summary b {
  color: #475569;
}

.m-contract-summary__buyer[open] summary b::before {
  content: "Скрыть";
  font-size: 0.72rem;
}

.m-contract-summary__buyer[open] summary b {
  font-size: 0;
}

.m-contract-summary__kv {
  display: grid;
  grid-template-columns: 5.8rem minmax(0, 1fr);
  gap: 0.45rem 0.65rem;
  margin: 0;
  padding: 0 0.8rem 0.85rem;
}

.m-contract-summary__kv dd {
  min-width: 0;
  margin: 0;
  color: #0f172a;
  font-size: 0.84rem;
  line-height: 1.34;
  overflow-wrap: anywhere;
}

.m-contract-summary__file,
.m-contract-summary__signed-file,
.m-contract-summary__upload {
  display: block;
  width: 100%;
  padding: 0.72rem 0.8rem;
  border: 0;
  border-radius: 16px;
  background: #0f7d50;
  color: #fff;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.m-contract-summary__signed-file {
  background: #eff6ff;
  color: #1d4ed8;
  overflow-wrap: anywhere;
}

.m-contract-summary__upload:disabled {
  opacity: 0.72;
}

.m-contract-photo-overlay[hidden] {
  display: none !important;
}

.m-contract-photo-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(3.4rem + var(--m-safe-top)) max(0.8rem, env(safe-area-inset-right))
    calc(1rem + var(--m-safe-bottom)) max(0.8rem, env(safe-area-inset-left));
  background: rgba(2, 6, 23, 0.88);
}

.m-contract-photo-overlay img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  object-fit: contain;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}

.m-contract-photo-overlay img[hidden],
.m-contract-photo-overlay iframe[hidden] {
  display: none !important;
}

.m-contract-photo-overlay iframe {
  width: min(100%, 62rem);
  height: 100%;
  border: 0;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}

.m-contract-photo-overlay__close {
  position: fixed;
  top: calc(0.72rem + var(--m-safe-top));
  right: max(0.75rem, env(safe-area-inset-right));
  width: 2.7rem;
  height: 2.7rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font: inherit;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
}

.m-contract-comment-modal[hidden] {
  display: none !important;
}

.m-contract-comment-modal {
  position: fixed;
  inset: 0 0 calc(var(--m-nav-h) + var(--m-safe-bottom)) 0;
  z-index: 98;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: max(0.8rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right))
    0.75rem max(0.75rem, env(safe-area-inset-left));
  overscroll-behavior: contain;
  touch-action: none;
}

body.m-keyboard-open .m-contract-comment-modal {
  bottom: 0;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.m-contract-comment-modal__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.55);
}

.m-contract-comment-modal__panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 0.7rem;
  width: min(100%, 30rem);
  max-height: calc(100dvh - var(--m-nav-h) - var(--m-safe-top) - var(--m-safe-bottom) - 1.5rem);
  overflow: auto;
  border-radius: 24px 24px 18px 18px;
  background: #fff;
  padding: 1rem;
  box-shadow: 0 -18px 48px rgba(15, 23, 42, 0.24);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

body.m-keyboard-open .m-contract-comment-modal__panel {
  max-height: calc(100dvh - var(--m-safe-top) - var(--m-safe-bottom) - 1.5rem);
}

.m-contract-comment-modal__panel h3,
.m-contract-comment-modal__subtitle,
.m-contract-comment-modal__error {
  margin: 0;
}

.m-contract-comment-modal__panel h3 {
  color: #0f172a;
  font-size: 1rem;
  line-height: 1.24;
}

.m-contract-comment-modal__subtitle {
  color: #64748b;
  font-size: 0.82rem;
  font-weight: 800;
}

.m-contract-comment-modal__pay {
  display: grid;
  gap: 0.35rem;
  color: #475569;
  font-size: 0.8rem;
  font-weight: 900;
}

.m-contract-comment-modal__pay input,
.m-contract-comment-modal__panel textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  background: #fff;
  color: #0f172a;
  font: inherit;
  font-size: 0.92rem;
  padding: 0.7rem 0.75rem;
}

.m-contract-comment-modal__panel textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.42;
}

.m-contract-comment-modal__label {
  color: #475569;
  font-size: 0.8rem;
  font-weight: 900;
}

.m-contract-comment-modal__error {
  color: #b91c1c;
  font-size: 0.82rem;
  font-weight: 800;
}

.m-contract-comment-modal__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.m-contract-comment-modal__row button,
.m-contract-comment-prior__actions button {
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 900;
}

.m-contract-comment-modal__row button {
  min-height: 2.6rem;
  background: #e2e8f0;
  color: #334155;
}

.m-contract-comment-modal__row button[type="submit"] {
  background: #0f7d50;
  color: #fff;
}

.m-contract-comment-modal__row button:disabled {
  opacity: 0.72;
}

.m-contract-comment-prior {
  display: grid;
  gap: 0.55rem;
}

.m-contract-comment-prior__row {
  display: grid;
  gap: 0.4rem;
}

.m-contract-comment-prior__item {
  border-left: 3px solid #0f7d50;
  border-radius: 12px;
  background: #ecfdf5;
  color: #0f172a;
  font-size: 0.86rem;
  line-height: 1.4;
  padding: 0.62rem 0.7rem;
  white-space: pre-wrap;
}

.m-contract-comment-prior__item--followup {
  border-left-color: #2563eb;
  background: #eff6ff;
}

.m-contract-comment-prior__item span {
  display: block;
  margin-bottom: 0.25rem;
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.m-contract-comment-prior__actions {
  display: flex;
  gap: 0.45rem;
}

.m-contract-comment-prior__actions button {
  padding: 0.42rem 0.65rem;
  background: #f1f5f9;
  color: #334155;
  font-size: 0.78rem;
}

.m-contract-manager-comment {
  margin-bottom: 0.7rem;
  padding: 0.65rem 0.75rem;
  border-left: 3px solid var(--m-accent);
  border-radius: 12px;
  background: var(--m-accent-soft);
}

.m-contract-manager-comment strong {
  display: block;
  color: var(--m-accent);
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}

.m-contract-manager-comment p {
  margin: 0;
  color: var(--m-text);
  font-size: 0.88rem;
  line-height: 1.42;
}

.m-contract-detail .m-btn + .m-btn {
  margin-top: 0.5rem;
}

.m-contract-items {
  display: grid;
  gap: 0.55rem;
}

.m-contract-item {
  display: grid;
  gap: 0.18rem;
  padding: 0.65rem 0;
  border-top: 1px solid var(--m-border);
}

.m-contract-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.m-contract-item strong {
  font-size: 0.9rem;
}

.m-contract-item span {
  color: var(--m-muted);
  font-size: 0.82rem;
}

.m-contract-full[hidden] {
  display: none !important;
}

.m-contract-full {
  flex: 0 0 auto;
  overflow: visible;
  width: max-content;
  max-width: none;
  margin: 0;
  padding-bottom: 0;
  transform-origin: top center;
}

.m-contract-full-doc {
  width: max(760px, 100%);
  min-height: 1060px;
  padding: 30px 34px;
  border: 1px solid #d1d5db;
  border-radius: 2px;
  background: #fff;
  color: #111827;
  font-family: Inter, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.m-contract-full-doc__header {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding-bottom: 10px;
  border-bottom: 4px solid #209465;
  text-align: center;
  text-transform: lowercase;
  color: #64748b;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.m-contract-full-doc__header img {
  display: block;
  width: 142px;
  height: auto;
}

.m-contract-full-doc h1 {
  margin: 10px 0 12px;
  text-align: center;
  font-size: 18px;
  line-height: 1.25;
}

.m-contract-full-doc h1 span {
  font-weight: 700;
}

.m-contract-full-doc h2 {
  margin: 22px 0 8px;
  font-size: 18px;
}

.m-contract-full-doc__lead {
  margin: 0 0 18px;
  font-weight: 700;
}

.m-contract-full-doc__bank {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.m-contract-full-doc__bank table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.m-contract-full-doc__bank td {
  border: 1px solid #d1d5db;
  padding: 5px 7px;
}

.m-contract-full-doc__bank td:first-child {
  background: #f3f4f6;
  color: #64748b;
  width: 32%;
}

.m-contract-full-doc__bank img {
  display: block;
  width: 84px;
  height: 84px;
}

.m-contract-full-doc__line {
  margin: 0 0 8px;
  padding: 7px 9px;
  border: 1px solid #e5e7eb;
  background: #f8fafc;
}

.m-contract-full-doc__grid {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 6px 12px;
  margin: 0;
}

.m-contract-full-doc__grid dt {
  color: #64748b;
  font-weight: 700;
}

.m-contract-full-doc__grid dd {
  margin: 0;
}

.m-contract-full-doc__table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 12px;
}

.m-contract-full-doc__table th,
.m-contract-full-doc__table td {
  border: 1px solid #d1d5db;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.m-contract-full-doc__table th,
.m-contract-full-doc__table tfoot td {
  background: #f3f4f6;
  font-weight: 800;
}

.m-contract-full-doc__terms {
  margin: 18px 0;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  background: #f8fafc;
  font-size: 11px;
}

.m-contract-full-doc__terms p {
  margin: 0 0 5px;
}

.m-contract-full-doc__terms p:last-child {
  margin-bottom: 0;
}

.m-contract-full-doc__footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}

.m-contract-full-doc__footer section {
  min-height: 230px;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  background: #f8fafc;
}

.m-contract-full-doc__footer h2 {
  margin: 0 0 10px;
  text-transform: uppercase;
  font-size: 13px;
}

.m-contract-full-doc__footer p {
  margin: 0 0 5px;
  font-size: 11px;
}

.m-contract-full-doc__signature {
  margin-top: 28px;
  padding-top: 8px;
  border-top: 1px solid #d1d5db;
  text-align: center;
  font-weight: 700;
}

.m-contract-full-doc a {
  color: #0f7d50;
  font-weight: 800;
}

.m-client-row__body a {
  color: var(--m-accent);
  font-weight: 600;
}

/* ----- Notifications ----- */
.m-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.m-muted {
  color: var(--m-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.m-kv {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.m-kv dt {
  margin: 0;
  color: var(--m-muted);
  font-weight: 500;
}

.m-kv dd {
  margin: 0;
  font-weight: 600;
}

/* ----- Mobile login (без редиректа на index) ----- */
.m-login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--m-safe-top, 0px) + 1rem) 1rem calc(var(--m-safe-bottom, 0px) + 1rem);
  box-sizing: border-box;
}

.m-login__panel {
  width: min(100%, 22rem);
  margin: 0;
}

.m-login__hint {
  margin: -0.35rem 0 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--m-muted, #64748b);
}
