:root {
  color-scheme: light;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #191919;
  background: #fff;
  --paper: #fff;
  --ink: #191919;
  --muted: #5c5c5c;
  --rail: #f7f7f6;
  --surface: #fafafa;
  --line: #e3e3e1;
  --edge: #b7b7b4;
  --selected: #eeeeec;
  --focus: #515151;
  --error: #a22435;
}

* { box-sizing: border-box; }
body { min-width: 280px; min-height: 100vh; margin: 0; }
::selection { color: #fff; background: #343434; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1, h2 { line-height: 1.18; letter-spacing: -.035em; overflow-wrap: anywhere; }
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 680; }
p { max-width: 68ch; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
button, input { transition: background-color .15s ease, border-color .15s ease; }
input:not([type='checkbox']) {
  width: 100%; padding: .68rem .78rem; border: 1px solid var(--edge); border-radius: 6px;
  background: var(--paper); color: var(--ink); caret-color: var(--ink);
}
input:not([type='checkbox']):hover { border-color: var(--focus); }
.initial { margin: 2rem auto; padding-inline: 1rem; color: var(--muted); }
.muted { color: var(--muted); }
.error { color: var(--error); }
.status { color: #31543b; font-size: .9rem; overflow-wrap: anywhere; }
.status.error { color: var(--error); }

.icon { width: 1.05rem; height: 1.05rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.55; stroke-linecap: round; stroke-linejoin: round; }
.primary, .quiet, .text-button, .nav-link, .nav-current {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.45rem; padding: .45rem .72rem; border: 1px solid transparent; border-radius: 6px;
  font-size: .9rem; font-weight: 620; line-height: 1.25;
}
.primary { color: #fff; background: #181818; }
.primary:hover:not(:disabled) { background: #3a3a3a; }
.quiet { color: var(--ink); background: var(--paper); border-color: var(--line); }
.quiet:hover:not(:disabled) { background: var(--surface); border-color: var(--edge); }
.text-button { color: var(--muted); background: transparent; }
.text-button:hover { color: var(--ink); background: var(--selected); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }

.brand { display: flex; align-items: center; gap: .65rem; letter-spacing: -.025em; white-space: nowrap; }
.mark { width: 2rem; height: 2rem; display: grid; place-items: center; background: #181818; color: #fff; border-radius: 6px; }
.mark .icon { width: 1.18rem; height: 1.18rem; }
.entry { min-height: 100svh; display: grid; place-items: center; padding: 1.25rem; background: var(--surface); }
.entry-content {
  display: grid; gap: 1.35rem; width: min(100%, 25rem); padding: 2rem;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
}
.entry-content > .brand { margin-bottom: .35rem; }
.entry-content h1 { font-size: 1.65rem; }
.form { display: grid; gap: .9rem; }
.field { display: grid; gap: .35rem; min-width: 0; font-size: .9rem; font-weight: 620; }
.field input { font-size: 1rem; font-weight: 400; }
.checkbox { display: flex; align-items: flex-start; gap: .55rem; font-size: .9rem; color: var(--ink); cursor: pointer; }
.checkbox input { width: 1rem; height: 1rem; flex: none; margin: .21rem 0 0; accent-color: var(--ink); }

.workspace { min-height: 100svh; display: grid; grid-template-columns: 13.75rem minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; min-height: 100dvh; max-height: 100dvh; align-self: start;
  display: flex; flex-direction: column; gap: 1.8rem; padding: 1.3rem 1rem .9rem;
  background: var(--rail); border-right: 1px solid var(--line);
}
.sidebar .brand { padding-inline: .3rem; }
.sidebar nav { display: grid; gap: .2rem; }
.nav-link, .nav-current { width: 100%; justify-content: flex-start; text-align: left; white-space: nowrap; }
.nav-link { background: transparent; color: var(--muted); }
.nav-link:hover { color: var(--ink); background: #f0f0ee; }
.nav-current { background: var(--selected); color: var(--ink); }
.account { display: grid; gap: .45rem; margin-top: auto; padding: .8rem .25rem 0; border-top: 1px solid var(--line); }
.account-details, .member-name { display: grid; min-width: 0; overflow-wrap: anywhere; }
.account-details span, .member-name span { color: var(--muted); font-size: .86rem; }
.account-actions { display: flex; flex-wrap: wrap; gap: .1rem; margin-inline-start: -.55rem; }
.account-actions .text-button { min-height: 2.05rem; padding-inline: .52rem; }
.main { min-width: 0; width: 100%; max-width: 105rem; padding: 1.75rem 1.8rem 1.5rem; }
.page-head { min-height: 2.45rem; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .9rem; margin-bottom: 1.15rem; }
.toolbar { justify-content: flex-end; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); gap: 1rem; align-items: start; }
.editor, .directory, .compose { background: var(--paper); border: 1px solid var(--line); border-radius: 9px; }
.editor, .compose { padding: 1.1rem; }
.editor > h2, .compose > h2 { margin-bottom: .95rem; }
.editor > .status { margin-bottom: .75rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .72rem 1.05rem; border-bottom: 1px solid var(--line); }
.empty, .members > .muted { padding: 1rem; color: var(--muted); overflow-wrap: anywhere; }
.empty.error { color: var(--error); }
.member { display: grid; gap: .65rem; padding: .8rem 1.05rem; }
.member + .member { border-top: 1px solid var(--line); }
.member-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .65rem; align-items: start; }
.pill { border-radius: 2rem; padding: .18rem .55rem; background: var(--selected); font-size: .83rem; color: var(--muted); }
.pill.active { background: #e8f2eb; color: #32543c; }
.credentials { margin-bottom: .9rem; padding: .95rem; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); overflow-wrap: anywhere; }
.credentials pre { margin: .5rem 0 .85rem; white-space: pre-wrap; font-size: .9rem; }
.credentials .status { margin-top: .5rem; }

.mail { display: grid; gap: .65rem; }
.mail-grid {
  display: grid; grid-template-columns: minmax(15rem, 29%) minmax(0, 1fr);
  min-height: 25rem; height: calc(100dvh - 7.3rem); overflow: hidden;
  border: 1px solid var(--line); border-radius: 9px; background: var(--paper);
}
.threads, .reading { min-width: 0; overflow: auto; overscroll-behavior: contain; scrollbar-color: #bcbcbc transparent; }
.threads { border-right: 1px solid var(--line); }
.reading-rest { display: grid; place-items: center; color: #aaa; background: var(--surface); }
.reading-rest .icon { width: 2rem; height: 2rem; stroke-width: 1.2; }
.reading:focus-visible, .thread:focus-visible { outline-offset: -3px; }
.threads > .quiet, .messages > .quiet { margin: .8rem; }
.thread {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .22rem .6rem;
  align-items: center; padding: .85rem .9rem; border: 0; border-bottom: 1px solid var(--line);
  color: var(--ink); background: var(--paper); text-align: left;
}
.thread:hover { background: var(--surface); }
.thread[aria-pressed='true'] { background: var(--selected); }
.correspondent, .thread-subject { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.correspondent { color: var(--muted); font-size: .86rem; }
.thread-subject { grid-column: 1; font-size: .95rem; font-weight: 570; }
.thread[data-unread='true'] .thread-subject, .thread[data-unread='true'] .correspondent { color: var(--ink); font-weight: 720; }
.unread-dot { justify-self: end; width: .45rem; height: .45rem; border-radius: 50%; background: var(--ink); }
.thread time, .message-meta time, .sender span { color: var(--muted); font-size: .83rem; }
.reader-head { display: grid; gap: .65rem; padding: .85rem 1.15rem .95rem; border-bottom: 1px solid var(--line); }
.reader-actions { justify-content: space-between; }
.reader-back { margin-inline-start: -.45rem; }
.reader-head h2 { font-size: 1.35rem; }
.mail-message { display: grid; gap: .7rem; padding: 1rem 1.15rem 1.15rem; }
.mail-message + .mail-message { border-top: 1px solid var(--line); }
.mail-message .quiet { justify-self: start; }
.message-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem .85rem; align-items: start; }
.sender { display: grid; min-width: 0; overflow-wrap: anywhere; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .96rem; }
.rich-body { white-space: normal; overflow-x: auto; }
.rich-body > :first-child { margin-top: 0; }
.rich-body > :last-child { margin-bottom: 0; }
.rich-body p + p { margin-top: .5rem; }
.rich-body pre { white-space: pre-wrap; }
.rich-body a { color: var(--ink); text-underline-offset: .15em; }
.rich-body blockquote { margin: .55rem 0; border-inline-start: 1px solid var(--edge); padding-inline-start: .85rem; }
.mail-message > .muted { overflow-wrap: anywhere; font-size: .875rem; }

.compose-dialog { width: min(calc(100% - 2rem), 42rem); max-height: calc(100dvh - 2rem); padding: 0; border: 0; border-radius: 11px; background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px #18181833; }
.compose-dialog::backdrop { background: #16161655; }
.compose-dialog .compose { border: 0; border-radius: 0; padding: 1.25rem; }
.compose .form { gap: .75rem; }
.reading .compose { margin: 0 1.15rem 1rem; }
.rich-editor { min-width: 0; border-radius: 6px; }
.rich-editor:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.rich-editor .ql-toolbar.ql-snow {
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; padding: .35rem .45rem;
  border-color: var(--edge); border-radius: 6px 6px 0 0; background: var(--surface);
}
.rich-editor .ql-toolbar.ql-snow .ql-formats { display: flex; gap: .12rem; margin: 0; }
.rich-editor .ql-formats + .ql-formats { padding-inline-start: .3rem; border-inline-start: 1px solid var(--line); }
.rich-editor .ql-toolbar button { width: 1.95rem; height: 1.95rem; padding: .32rem; border-radius: 4px; color: var(--ink); }
.rich-editor .ql-toolbar button:hover, .rich-editor .ql-toolbar button.ql-active { background: var(--selected); }
.rich-editor .ql-toolbar button:is(:hover, .ql-active) .ql-stroke { stroke: var(--ink); }
.rich-editor .ql-toolbar button:is(:hover, .ql-active) .ql-fill { fill: var(--ink); }
.rich-editor .ql-container.ql-snow { height: auto; border-color: var(--edge); border-radius: 0 0 6px 6px; font: 400 1rem/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.rich-editor .ql-editor { min-height: 10.5rem; max-height: 42vh; caret-color: var(--ink); }
.rich-editor .ql-editor a { color: var(--ink); }
.rich-editor .ql-tooltip { z-index: 2; border-radius: 6px; max-width: 100%; }
.rich-editor .ql-tooltip.ql-hidden { display: none; }
.rich-editor .ql-tooltip::before, .rich-editor .ql-tooltip[data-mode=link]::before { content: none; }
.rich-editor .ql-tooltip input[type=text] { width: min(37vw, 14rem); }
.rich-editor .ql-tooltip a.ql-preview { max-width: min(31vw, 10rem); }
.rich-editor .ql-tooltip a.ql-action::after { content: 'Изменить'; margin-left: .5rem; }
.rich-editor .ql-tooltip.ql-editing a.ql-action::after { content: 'Сохранить'; }
.rich-editor .ql-tooltip a.ql-remove::before { content: 'Удалить'; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 11.5rem minmax(0, 1fr); }
  .sidebar { padding-inline: .7rem; }
  .main { padding-inline: 1rem; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-grid .editor { grid-row: 1; }
}
@media (max-width: 740px) {
  .workspace { display: block; }
  .sidebar { position: static; min-height: auto; max-height: none; gap: .55rem; padding: .75rem .9rem .5rem; border: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand { padding: 0; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: .22rem; }
  .sidebar nav > * { width: auto; }
  .sidebar nav .icon { width: .9rem; height: .9rem; }
  .account { padding: .45rem 0 0; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .account-actions { margin: 0; }
  .account .status { grid-column: 1/-1; }
  .main { padding: 1rem .9rem; }
  .page-head { gap: .65rem; margin-bottom: .85rem; }
  h1 { font-size: 1.5rem; }
  .toolbar { justify-content: flex-start; }
  .mail-grid { display: block; height: auto; min-height: 0; overflow: visible; }
  .threads, .reading { overflow: visible; }
  .threads { border: 0; }
  .reading-rest, .has-reader .threads { display: none; }
  .thread:last-child { border-bottom: 0; }
  .reading .compose { margin-inline: .65rem; }
  .entry-content { padding: 1.4rem; }
}
@media (max-width: 400px) {
  .sidebar nav .icon { display: none; }
  .account-actions .text-button { padding-inline: .35rem; }
  .compose-dialog .compose { padding: .85rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
