@layer reset, base, layout, components, mobile;
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p { margin: 0; }
  button, input, select, textarea { font: inherit; }
  button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
  button { cursor: pointer; }
  img { max-width: 100%; }
}
@layer base {
  :root { color-scheme: light dark; --bg: #f4f7f6; --panel: #fff; --panel-soft: #f8faf9; --text: #1c302e; --muted: #62736f; --line: #e2e9e6; --accent: #147d75; --accent-hover: #0c665f; --tint: #e6f3ee; --tint-text: #17645b; --bubble: #edf2ef; --danger: #b5353e; --shadow: 0 16px 60px #183a2e12; font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
  @media (prefers-color-scheme: dark) { :root { --bg: #101a19; --panel: #182421; --panel-soft: #1c2a27; --text: #e7f0ed; --muted: #a0b4ad; --line: #2d3c37; --accent: #39b5a6; --accent-hover: #63cdbc; --tint: #203c34; --tint-text: #8ddac3; --bubble: #263b34; --danger: #ff9a9f; --shadow: 0 16px 60px #0002; } }
  body { background: var(--bg); color: var(--text); line-height: 1.5; }
  a { color: var(--accent); text-decoration: none; }
  button { color: inherit; background: transparent; border: 0; }
  :focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
  input, textarea, select { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; min-width: 0; }
  input::placeholder, textarea::placeholder { color: var(--muted); opacity: .9; }
  textarea { resize: vertical; }
  label { display: grid; gap: 7px; font-weight: 600; font-size: .92rem; }
  label input, label textarea, label select { font-weight: 400; }
  h1 { font-size: 1.85rem; letter-spacing: -.055em; font-weight: 700; }
  h2 { font-size: 1.2rem; letter-spacing: -.025em; }
  h3 { font-size: 1rem; }
  small, .muted { color: var(--muted); }
  .icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
  .skip { position: fixed; top: -70px; left: 20px; padding: 10px 20px; z-index: 100; background: var(--panel); }
  .skip:focus { top: 10px; }
}
@layer layout {
  .app-shell { height: 100dvh; display: grid; grid-template-columns: 218px minmax(0, 1fr); overflow: hidden; }
  .sidebar { display: flex; flex-direction: column; padding: 32px 18px 20px; border-right: 1px solid var(--line); background: var(--panel-soft); gap: 25px; }
  .brand { display: flex; gap: 10px; align-items: center; padding: 0 10px; font-size: 1.55rem; font-weight: 750; letter-spacing: -.06em; }
  .brand img { width: 34px; height: 34px; border-radius: 11px; }
  .workspace-label { font-size: .7rem; letter-spacing: .12em; color: var(--muted); font-weight: 650; padding: 0 13px; margin-bottom: 10px; }
  .nav { display: grid; gap: 6px; }
  .nav button { min-height: 46px; display: flex; align-items: center; gap: 12px; text-align: left; padding: 11px 13px; border-radius: 10px; color: var(--muted); font-weight: 550; }
  .nav button:hover { background: var(--bubble); color: var(--text); }
  .nav button.active { background: var(--tint); color: var(--tint-text); }
  .nav .count { margin-left: auto; }
  .sidebar-bottom { margin-top: auto; display: grid; gap: 18px; }
  .number-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
  .number-card label { color: var(--muted); font-size: .74rem; }
  .number-card select { width: 100%; padding: 6px 0; border: 0; border-radius: 0; font-size: .9rem; font-weight: 600; background: transparent; }
  .number-card p { margin-top: 4px; font-size: .9rem; }
  .profile { display: flex; align-items: center; gap: 9px; padding: 0 4px; }
  .profile-copy { min-width: 0; flex: 1; }
  .profile-copy strong, .profile-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .profile-copy strong { font-size: .88rem; }
  .profile-copy small { font-size: .75rem; }
  .main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
  .topbar { display: flex; align-items: center; gap: 20px; min-height: 96px; padding: 22px 32px; border-bottom: 1px solid var(--line); background: var(--panel); }
  .topbar-title { flex: 1; }
  .topbar-title p { color: var(--muted); font-size: .86rem; margin-top: 2px; }
  .topbar .search { width: min(340px, 40%); }
  .workspace { display: grid; grid-template-columns: 345px minmax(0, 1fr); min-height: 0; flex: 1; }
  .inbox-pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
  .conversation-list { overflow: auto; flex: 1; overscroll-behavior: contain; padding: 8px 10px 20px; }
  .thread-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel-soft); }
  .thread-header { padding: 19px 24px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 84px; }
  .thread-title { flex: 1; min-width: 0; }
  .thread-title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .thread-title p { font-size: .8rem; color: var(--muted); }
  .thread-actions { display: flex; align-items: center; gap: 3px; }
  .messages { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 26px clamp(18px, 5vw, 70px); display: flex; flex-direction: column; gap: 16px; }
  .composer-wrap { padding: 16px 24px max(20px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
  .composer { display: flex; gap: 10px; align-items: flex-end; padding: 6px; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 16px; }
  .composer textarea { min-height: 42px; max-height: 160px; flex: 1; border: 0; resize: none; background: transparent; padding: 10px 4px; outline-offset: 0; }
  .composer-note { text-align: center; color: var(--muted); font-size: .72rem; margin-top: 9px; }
  .page-scroll { overflow: auto; padding: 30px 34px 60px; }
  .page-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; max-width: 1150px; }
  .wide { grid-column: 1 / -1; }
  .mobile-only, .mobile-nav { display: none; }
}
@layer components {
  .btn { min-height: 42px; padding: 10px 16px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; border: 1px solid var(--line); background: var(--panel); white-space: nowrap; }
  .btn:hover { background: var(--bubble); }
  .btn.primary { background: var(--accent); color: var(--on-accent, #fff); border-color: transparent; }
  .btn.primary:hover { background: var(--accent-hover); }
  .btn.soft { background: var(--tint); color: var(--tint-text); border-color: transparent; }
  .btn.danger, .danger-text { color: var(--danger); }
  .btn.small { padding: 7px 11px; min-height: 34px; font-size: .8rem; }
  .icon-btn { width: 40px; height: 40px; display: inline-flex; justify-content: center; align-items: center; border-radius: 10px; flex-shrink: 0; color: var(--muted); }
  .icon-btn:hover, .icon-btn.selected { background: var(--tint); color: var(--tint-text); }
  button:disabled { opacity: .5; cursor: default; }
  .avatar { width: 43px; height: 43px; border-radius: 50%; display: grid; place-items: center; background: var(--tint); color: var(--tint-text); font-weight: 650; flex-shrink: 0; font-size: .95rem; }
  .avatar-0 { background: #dcefe9; color: #205d4d; }
  .avatar-1 { background: #e5e5fa; color: #51438a; }
  .avatar-2 { background: #dceaf9; color: #285c88; }
  .avatar-3 { background: #f9e4d5; color: #874923; }
  .avatar-4 { background: #f5dfeb; color: #853a64; }
  .avatar-5 { background: #ececcf; color: #5d601d; }
  .avatar.small { width: 34px; height: 34px; font-size: .8rem; }
  .count { background: var(--accent); color: var(--on-accent, #fff); border-radius: 20px; min-width: 20px; padding: 1px 6px; font-size: .7rem; text-align: center; font-weight: 700; }
  .search { display: flex; align-items: center; gap: 10px; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; color: var(--muted); }
  .search input { background: transparent; padding: 10px 0; border: 0; width: 100%; font-size: .9rem; }
  .code-card { margin: 18px 18px 8px; padding: 15px; border: 1px solid #9bcabd55; border-radius: 13px; background: var(--tint); color: var(--tint-text); }
  .code-card.expired { background: var(--panel-soft); color: var(--muted); border-color: var(--line); }
  .code-card.expired .code-digits > strong { opacity: .65; }
  .code-card [data-copy-label] { display: inline-flex; align-items: center; gap: 7px; }
  .code-card .btn { min-width: 110px; }
  .code-eyebrow { display: flex; gap: 7px; align-items: center; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; }
  .code-eyebrow .icon { width: 15px; height: 15px; }
  .code-eyebrow .live-dot { width: 6px; height: 6px; margin-left: auto; border-radius: 50%; background: var(--accent); }
  .code-digits { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 7px; }
  .code-digits strong { font-size: 1.9rem; letter-spacing: .1em; font-weight: 650; font-variant-numeric: tabular-nums; }
  .code-card p { font-size: .78rem; }
  .list-heading { display: flex; gap: 8px; align-items: center; padding: 14px 23px 8px; color: var(--muted); font-size: .76rem; }
  .list-heading strong { color: var(--text); }
  .list-heading .list-total { margin-left: auto; }
  .conversation { width: 100%; display: flex; gap: 12px; padding: 15px 12px; border-radius: 12px; text-align: left; margin-bottom: 3px; }
  .conversation:hover { background: var(--panel-soft); }
  .conversation.active { background: var(--tint); }
  .conversation-copy { min-width: 0; flex: 1; }
  .conversation-top, .conversation-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .conversation-top strong { font-size: .92rem; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .conversation-top time { font-size: .68rem; color: var(--muted); white-space: nowrap; }
  .conversation-bottom { margin-top: 5px; }
  .conversation-bottom p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: .85rem; }
  .conversation.unread .conversation-bottom p { color: var(--text); font-weight: 500; }
  .conversation-bottom .icon { width: 12px; height: 12px; color: var(--muted); }
  .empty { display: grid; place-content: center; text-align: center; padding: 40px 25px; flex: 1; color: var(--muted); gap: 12px; }
  .empty h2 { color: var(--text); font-size: 1.6rem; letter-spacing: -.045em; }
  .empty p { max-width: 330px; margin: 0 auto; }
  .empty .empty-mark { margin: 0 auto 9px; background: var(--tint); color: var(--accent); width: 80px; height: 80px; border-radius: 26px; display: grid; place-items: center; transform: rotate(-7deg); }
  .empty-mark .icon { width: 36px; height: 36px; transform: rotate(7deg); }
  .empty.compact { padding: 40px 16px; font-size: .9rem; }
  .empty.compact h2 { font-size: 1.2rem; }
  .date-divider { align-self: center; color: var(--muted); font-size: .7rem; padding: 4px 10px; margin: 5px 0 10px; }
  .message { align-self: flex-start; max-width: min(84%, 540px); display: flex; flex-direction: column; gap: 5px; content-visibility: auto; contain-intrinsic-size: auto 90px; }
  .message.out { align-self: flex-end; align-items: flex-end; }
  .bubble { border-radius: 17px 17px 17px 5px; background: var(--bubble); padding: 13px 17px; line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; }
  .out .bubble { border-radius: 17px 17px 5px 17px; background: var(--accent); color: var(--on-accent, #fff); }
  .message-meta { display: flex; align-items: center; gap: 5px; font-size: .68rem; color: var(--muted); padding: 0 4px; }
  .message-meta .icon { width: 13px; height: 13px; }
  .otp-button { margin-top: 12px; display: flex; justify-content: space-between; gap: 24px; width: 100%; border-top: 1px solid var(--line); padding-top: 12px; color: var(--tint-text); font-weight: 650; align-items: center; white-space: normal; }
  .otp-button strong { font-variant-numeric: tabular-nums; letter-spacing: .16em; font-size: 1.35rem; }
  .otp-button span { font-size: .8rem; display: flex; gap: 6px; align-items: center; }
  .message-media { display: block; max-height: 360px; border-radius: 12px; object-fit: contain; margin-bottom: 6px; }
  .attachment-list { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 10px; }
  .attachment-chip { display: flex; gap: 6px; align-items: center; border-radius: 8px; background: var(--tint); color: var(--tint-text); padding: 5px 9px; font-size: .78rem; }
  .banner { background: var(--tint); color: var(--tint-text); padding: 9px 20px; font-size: .82rem; text-align: center; border-bottom: 1px solid var(--line); }
  .banner.warning { background: #fff0d4; color: #705118; }
  .card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
  .card h2 { margin-bottom: 7px; }
  .card > p { color: var(--muted); font-size: .9rem; margin-bottom: 20px; }
  .stack { display: grid; gap: 16px; }
  .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .row .grow { flex: 1; min-width: 0; }
  .record { padding: 15px 0; border-bottom: 1px solid var(--line); }
  .record:last-child { border-bottom: 0; }
  .record p { color: var(--muted); font-size: .84rem; white-space: pre-wrap; overflow-wrap: anywhere; }
  .record .btn { margin-top: 6px; }
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .checks { display: flex; gap: 10px 18px; flex-wrap: wrap; margin: 12px 0; }
  .checks label { display: flex; align-items: center; gap: 8px; font-weight: 400; }
  input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
  .tag { padding: 3px 7px; font-size: .7rem; border-radius: 6px; background: var(--tint); color: var(--tint-text); }
  .auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(ellipse at 15% 10%, var(--tint), transparent 70%); }
  .auth-card { width: min(430px, 100%); padding: 38px; background: var(--panel); border: 1px solid var(--line); border-radius: 23px; box-shadow: var(--shadow); }
  .auth-card .brand { padding: 0; margin-bottom: 36px; }
  .auth-card h1 { margin-bottom: 8px; }
  .auth-card > p { color: var(--muted); margin-bottom: 26px; }
  .auth-footer { text-align: center; font-size: .76rem; margin-top: 22px; color: var(--muted); }
  .error { color: var(--danger); font-size: .85rem; }
  #toast { position: fixed; bottom: max(30px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 200; background: var(--text); color: var(--panel); border-radius: 11px; padding: 12px 20px; box-shadow: var(--shadow); max-width: calc(100% - 32px); pointer-events: none; opacity: 0; transition: opacity .15s; }
  #toast.visible { opacity: 1; }
  dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); padding: 26px; width: min(480px, calc(100% - 28px)); box-shadow: var(--shadow); max-height: 90dvh; overflow-y: auto; }
  dialog::backdrop { background: #071b1866; backdrop-filter: blur(3px); }
  .dialog-heading { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 20px; }
  .dialog-heading h2 { font-size: 1.4rem; }
  .loading { min-height: 50dvh; display: grid; place-items: center; color: var(--muted); }
  .secret { word-break: break-all; padding: 14px; background: var(--bubble); border-radius: 10px; font-family: monospace; user-select: all; }
  .hidden { display: none !important; }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
  @media (prefers-color-scheme: dark) { :root { --on-accent: #062c27; } }
}
@layer mobile {
  @media (max-width: 1150px) and (min-width: 761px) {
    .app-shell { grid-template-columns: 80px minmax(0, 1fr); }
    .sidebar { padding: 30px 12px 20px; align-items: center; }
    .brand { padding: 0; }
    .sidebar .brand span, .sidebar .nav-label, .sidebar .workspace-label, .sidebar .profile-copy, .sidebar .number-card, .sidebar .profile > button { display: none; }
    .sidebar .nav button { justify-content: center; position: relative; }
    .sidebar .nav .count { position: absolute; right: -2px; top: 0; }
    .workspace { grid-template-columns: 315px minmax(0, 1fr); }
    .sidebar-bottom { width: 100%; }
    .profile { justify-content: center; }
    .topbar { padding: 20px 24px; }
  }
  @media (max-width: 760px) {
    :root { font-size: 15px; }
    .app-shell { grid-template-columns: 1fr; height: 100dvh; }
    .sidebar { display: none; }
    .main { padding-top: env(safe-area-inset-top); }
    .mobile-only { display: inline-flex; }
    .topbar { padding: 18px 20px 14px; min-height: 90px; flex-wrap: wrap; gap: 12px; }
    .topbar-title h1 { font-size: 2rem; }
    .topbar-title p { font-size: .75rem; }
    .topbar .search { order: 3; width: 100%; }
    .topbar .new-label { display: none; }
    .topbar .btn { width: 43px; padding: 10px; }
    .workspace { display: flex; }
    .inbox-pane { width: 100%; border: 0; }
    .thread-pane { display: none; width: 100%; }
    .has-thread .inbox-pane, .has-thread .topbar, .has-thread .mobile-nav { display: none; }
    .has-thread .thread-pane { display: flex; }
    .thread-header { padding: 12px 10px; gap: 7px; min-height: 76px; }
    .thread-header .avatar { width: 36px; height: 36px; font-size: .8rem; }
    .thread-title h2 { font-size: 1rem; }
    .thread-actions { gap: 0; }
    .thread-actions .icon-btn { width: 34px; }
    .thread-actions .desktop-action { display: none; }
    .messages { padding: 20px 15px; gap: 15px; }
    .message { max-width: 88%; }
    .bubble { padding: 12px 15px; }
    .composer-wrap { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
    .composer-note { font-size: .65rem; }
    .mobile-nav { display: flex; justify-content: space-around; padding: 8px 12px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
    .mobile-nav button { flex: 1; min-width: 0; padding: 5px 4px; color: var(--muted); display: grid; justify-items: center; gap: 3px; font-size: .63rem; border-radius: 10px; }
    .mobile-nav .nav-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
    .mobile-nav button.active { color: var(--accent); background: var(--tint); }
    .code-card { margin: 14px 20px 6px; }
    .code-digits strong { font-size: 2rem; }
    .list-heading { padding: 16px 24px 10px; }
    .conversation-list { padding: 2px 10px 14px; }
    .conversation { padding: 16px 12px; }
    .conversation .avatar { width: 47px; height: 47px; }
    .page-scroll { padding: 20px 16px 36px; }
    .page-grid, .form-grid { grid-template-columns: 1fr; }
    .card { padding: 21px; }
    .auth-card { padding: 28px; }
    .row .btn { white-space: normal; }
    input, select, textarea { font-size: 16px; }
    #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  }
}
