:root {
  color-scheme: dark;
  --bg: #07101d;
  --surface: #101c2c;
  --surface-2: #162438;
  --line: #263a53;
  --text: #f4f8ff;
  --muted: #93a5ba;
  --primary: #62a8ff;
  --danger: #ff7285;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif; }
button, input, textarea, select { font: inherit; }
button { border: 0; border-radius: 10px; padding: 10px 15px; background: var(--primary); color: #06101d; font-weight: 750; cursor: pointer; }
button:hover { filter: brightness(1.08); }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--muted); }
button.danger { color: var(--danger); }
.hidden { display: none !important; }

.login-card { width: min(440px, calc(100% - 32px)); margin: 10vh auto; padding: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 24px 80px #0008; }
.brand { font-weight: 900; font-size: 22px; color: var(--primary); }
.brand span { color: var(--muted); font-weight: 600; }
h1, h2, p { margin-top: 0; }
.login-card p, .section-title p { color: var(--muted); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, textarea, select { width: 100%; color: var(--text); background: #091522; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #62a8ff20; }
textarea { min-height: 92px; resize: vertical; }
.login-card form, .limit-form { display: grid; gap: 16px; margin-top: 24px; }
.limit-form { max-width: 420px; margin-top: 0; }
.error { min-height: 20px; color: var(--danger); }

.topbar { position: sticky; top: 0; z-index: 5; min-height: 70px; display: flex; align-items: center; gap: 20px; padding: 12px 24px; background: #081321ee; border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.topbar > div:first-child { display: grid; }
.topbar strong { color: var(--primary); font-size: 19px; }
.topbar span, .revision { color: var(--muted); font-size: 12px; }
.revision { margin-left: auto; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.workspace { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 70px); }
.sidebar { padding: 24px 14px; border-right: 1px solid var(--line); background: #091522; }
.sidebar button { display: block; width: 100%; margin-bottom: 7px; text-align: left; background: transparent; color: var(--muted); }
.sidebar button.nav-active { background: var(--surface-2); color: var(--text); }
.editor { padding: 36px; max-width: 1200px; width: 100%; margin: 0 auto; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.section-title h1 { margin-bottom: 4px; }
.section-title p { margin-bottom: 0; }
.search { max-width: 320px; }

.section-flag {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.section-flag input {
  width: auto;
  margin-top: 3px;
  accent-color: var(--primary);
}
.section-flag strong { display: block; margin-bottom: 4px; }
.section-flag small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; }

.text-list, .module-list, .history-list { display: grid; gap: 12px; }
.text-row, .module-card, .history-row { padding: 17px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.text-row { display: grid; grid-template-columns: minmax(170px, 280px) 1fr; align-items: start; gap: 18px; }
.text-meta { min-width: 0; color: var(--muted); font-size: 12px; }
.text-meta strong { display: block; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.text-row textarea { min-height: 70px; }
.module-head, .history-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.module-head h2 { margin: 0; font-size: 18px; }
.module-actions { display: flex; gap: 6px; }
.module-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.module-fields .wide { grid-column: 1 / -1; }
.items { grid-column: 1 / -1; display: grid; gap: 8px; }
.item-row { display: grid; grid-template-columns: 120px 1fr 2fr auto; gap: 8px; align-items: start; padding: 10px; background: #091522; border-radius: 10px; }
.item-row textarea { min-height: 44px; }
.muted { color: var(--muted); }

.mail-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mail-toolbar select { width: auto; min-width: 200px; }
.mail-layout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 14px;
  min-height: 420px;
}
.mail-list, .mail-detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  overflow: auto;
  max-height: calc(100vh - 220px);
}
.mail-item {
  display: grid;
  gap: 2px;
  width: 100%;
  margin-bottom: 8px;
  text-align: left;
  background: #091522;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 12px;
}
.mail-item.unread { border-color: var(--primary); }
.mail-item strong { font-size: 13px; }
.mail-item span, .mail-item small { color: var(--muted); font-size: 12px; font-weight: 500; }
.mail-detail-head h2 { margin: 0 0 8px; font-size: 18px; }
.mail-body {
  white-space: pre-wrap;
  word-break: break-word;
  background: #091522;
  border-radius: 10px;
  padding: 14px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.45;
}
.mail-detail-actions { display: flex; gap: 8px; }

dialog { width: min(560px, calc(100% - 28px)); color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
dialog::backdrop { background: #020711d9; }
dialog form { display: grid; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.preview-dialog { width: 96vw; max-width: none; height: 94vh; padding: 0; overflow: hidden; }
.preview-head { height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.preview-dialog iframe { width: 100%; height: calc(94vh - 58px); border: 0; background: white; }
.toast { position: fixed; right: 20px; bottom: 20px; padding: 12px 16px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; opacity: 0; transform: translateY(12px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 800px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .revision { margin-left: 0; }
  .top-actions { width: 100%; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar button { min-width: max-content; margin: 0; }
  .editor { padding: 22px 14px; }
  .section-title, .text-row { display: grid; grid-template-columns: 1fr; }
  .search { max-width: none; }
  .module-fields { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr; }
  .mail-layout { grid-template-columns: 1fr; }
  .mail-list, .mail-detail { max-height: 320px; }
}
