:root {
  --wine: #320707;
  --red: #E40000;
  --cream: #F6EDE3;
  --bg: #F6EDE3;
  --surface: #FFFFFF;
  --surface-2: #EFE3D6;
  --text: #320707;
  --muted: #7A5A55;
  --line: #E3D3C3;
  --mine: #320707;
  --mine-text: #F6EDE3;
  --btn: #FFFFFF;
  --btn-text: #320707;
  --accent: #E40000;
  --shadow: 0 1px 2px rgba(50, 7, 7, .08);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A0606;
    --surface: #2A0D0D;
    --surface-2: #361414;
    --text: #F6EDE3;
    --muted: #C9AFA6;
    --line: #4A2020;
    --mine: #F6EDE3;
    --mine-text: #320707;
    --btn: #361414;
    --btn-text: #F6EDE3;
    --accent: #FF4D4D;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1A0606; --surface: #2A0D0D; --surface-2: #361414; --text: #F6EDE3; --muted: #C9AFA6;
  --line: #4A2020; --mine: #F6EDE3; --mine-text: #320707; --btn: #361414; --btn-text: #F6EDE3;
  --accent: #FF4D4D; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ── вход ── */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 28px; }
.brand-word { display: block; font-size: 34px; font-weight: 800; letter-spacing: .02em; color: var(--text); }
.brand-word b { font-weight: 300; }
.brand-sub { display: block; margin-top: 6px; color: var(--muted); font-size: 14px; }
.form { display: grid; gap: 14px; background: var(--surface); padding: 22px 18px; border-radius: var(--radius);
        box-shadow: var(--shadow); border: 1px solid var(--line); }
.form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.form input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
              border-radius: 12px; padding: 12px 14px; min-height: 46px; }
.form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { margin: 0; color: var(--accent); font-size: 14px; min-height: 1em; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.btn { border: 0; border-radius: 12px; min-height: 46px; padding: 0 16px; font-weight: 600; }
.btn.primary { background: var(--wine); color: var(--cream); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { background: var(--cream); color: var(--wine); } }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 6px; }

/* ── приложение ── */
.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
       width: 100%; max-width: 720px; margin: 0 auto; overflow: hidden; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
       background: var(--wine); color: var(--cream); }
.who { display: grid; min-width: 0; flex: 1; }
#me-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#me-role { font-size: 12px; opacity: .75; }
.tabs { display: flex; flex: none; gap: 4px; background: rgba(246, 237, 227, .12); border-radius: 999px; padding: 3px; }
.tab { border: 0; background: none; color: var(--cream); padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.tab[aria-selected="true"] { background: var(--cream); color: var(--wine); font-weight: 600; }
.icon-btn { border: 0; background: none; min-width: 44px; min-height: 44px; border-radius: 12px; font-size: 20px; }
.top .icon-btn { color: var(--cream); }

.chat { overflow-y: auto; padding: 12px 16px 8px; display: flex; flex-direction: column; gap: 8px;
        overscroll-behavior: contain; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2);
       padding: 3px 10px; border-radius: 999px; margin: 6px 0; }
.msg { max-width: 88%; min-width: 0; display: grid; gap: 6px; }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; }
.bubble { padding: 10px 13px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere;
          box-shadow: var(--shadow); }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.user .bubble { background: var(--mine); color: var(--mine-text); border-top-right-radius: 6px; }
.bubble a { color: inherit; }
.bubble code, .bubble pre { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.meta { font-size: 11px; color: var(--muted); padding: 0 4px; }
.msg.user .meta { text-align: right; }
.photo { display: block; max-width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.file-chip { display: inline-flex; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 12px;
             background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 14px; }
.inline { display: grid; gap: 6px; }
.inline-row { display: flex; gap: 6px; }
.inline-row button { flex: 1; min-width: 0; min-height: 42px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line);
                     background: var(--btn); color: var(--btn-text); font-size: 14px; text-align: center; line-height: 1.25; }
.inline-row button:active { transform: scale(.98); }
.inline-row button:disabled { opacity: .5; }

.bottom { background: var(--surface); border-top: 1px solid var(--line);
          padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); display: grid; gap: 8px; }
.keyboard { display: grid; gap: 6px; }
.keyboard:empty { display: none; }
.kb-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.kb-row button { min-height: 44px; border-radius: 12px; border: 0; background: var(--surface-2);
                 color: var(--text); font-size: 15px; padding: 6px 8px; min-width: 0;
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer { display: flex; gap: 6px; align-items: center; }
.composer input[type="text"], #text-input { flex: 1; min-width: 0; font: inherit; color: var(--text);
               background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
               padding: 10px 14px; min-height: 44px; }
#text-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn.send { background: var(--wine); color: var(--cream); border-radius: 999px; font-size: 18px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .icon-btn.send { background: var(--cream); color: var(--wine); } }

.menu { position: fixed; inset: 0; background: rgba(20, 3, 3, .45); display: grid; align-items: end; z-index: 20; }
.menu-sheet { background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0; max-height: 80vh;
              overflow-y: auto; padding: 14px 12px calc(env(safe-area-inset-bottom) + 14px); max-width: 720px;
              width: 100%; margin: 0 auto; }
.menu-title { font-weight: 700; padding: 4px 8px 10px; }
.menu-item { display: grid; width: 100%; text-align: left; background: none; border: 0; padding: 12px 10px;
             border-radius: 12px; min-height: 44px; }
.menu-item small { color: var(--muted); }
.menu-item:active { background: var(--surface-2); }
.menu-item.danger { color: var(--accent); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 150px); margin: 0 auto;
         max-width: 420px; background: var(--wine); color: var(--cream); padding: 12px 16px; border-radius: 14px;
         text-align: center; z-index: 30; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.empty { color: var(--muted); text-align: center; margin: auto; padding: 24px; }

/* ── пароль с глазиком ── */
.pw { position: relative; display: block; }
.pw input { width: 100%; padding-right: 52px; }
.eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px;
       border: 0; background: none; font-size: 20px; opacity: .55; border-radius: 10px; }
.eye[aria-pressed="true"] { opacity: 1; }
.form-title { margin: 0; font-weight: 700; font-size: 18px; color: var(--text); }
.form.flat { box-shadow: none; border: 0; padding: 4px 0 0; }

/* ── листы: сотрудники, ссылка, пароль ── */
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head .menu-title { padding: 4px 8px; }
.menu-sheet .hint { padding: 0 8px; margin: 0 0 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 8px 12px; }
.chip { border: 1px solid var(--line); background: var(--btn); color: var(--btn-text); border-radius: 999px;
        padding: 8px 14px; min-height: 40px; font-size: 14px; }
.people { display: grid; gap: 8px; padding: 0 8px; }
.person { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 6px; }
.person.off { opacity: .55; }
.person-name { font-weight: 600; }
.person-meta { font-size: 13px; color: var(--muted); }
.person-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.person-actions button { border: 1px solid var(--line); background: var(--btn); color: var(--btn-text);
                         border-radius: 10px; padding: 6px 10px; min-height: 36px; font-size: 13px; }
.person-actions .danger { color: var(--accent); }
.link-value { width: calc(100% - 16px); margin: 0 8px 12px; font: 14px ui-monospace, Menlo, monospace;
              color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.btn:not(.primary) { background: var(--surface-2); color: var(--text); }

.add-form { display: grid; gap: 10px; padding: 0 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.add-form .menu-title { padding: 0; }
.add-form input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
                  border-radius: 12px; padding: 12px 14px; min-height: 46px; }
.add-form .chip-row { padding: 0; }
.chip[aria-checked="true"] { background: var(--wine); color: var(--cream); border-color: var(--wine); }
.creds { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; padding: 4px 8px 16px; align-items: baseline; }
.creds span { color: var(--muted); font-size: 14px; }
.creds b { font: 600 20px ui-monospace, Menlo, monospace; letter-spacing: .04em; user-select: all; }
