:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f7f9f8;
  --surface-strong: #eef4f2;
  --text: #111827;
  --muted: #667085;
  --border: #d9e1de;
  --accent: #4f7f78;
  --accent-dark: #315f59;
  --action: #d99a37;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(17, 24, 39, 0.12);
  --radius: 8px;
  --sidebar: 280px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #fbfcfc;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.nav-list,
.sidebar-actions {
  display: grid;
  gap: 12px;
}

.nav-item,
.ghost-button,
.secondary-button,
.primary-button,
.icon-button,
.text-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
}

.nav-item {
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 0 18px;
  font-size: 17px;
  text-align: left;
}

.nav-item.is-active,
.nav-item:hover {
  background: var(--surface-strong);
  color: var(--accent-dark);
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: inherit;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(79, 127, 120, 0.2);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #f7eddd;
  color: #80530d;
}

.ghost-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.ghost-button.danger {
  color: var(--danger);
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  background: var(--text);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}

.text-button {
  background: transparent;
  color: var(--accent-dark);
  padding: 0;
}

.account-box {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: grid;
  gap: 12px;
}

.account-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.avatar,
.avatar-preview {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--accent-dark);
  display: grid;
  place-items: center;
  font-weight: 800;
  overflow: hidden;
  border: 1px solid var(--border);
}

.avatar img,
.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.account-name {
  display: block;
  font-size: 14px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-mail {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  background: var(--surface);
}

.workspace[data-active-panel="reader"] {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.workspace[data-active-panel="settings"] {
  grid-template-columns: minmax(340px, 480px) minmax(380px, 1fr);
}

.feed-panel,
.reader-panel,
.profile-panel {
  min-width: 0;
  padding: clamp(26px, 3vw, 48px);
}

.feed-panel,
.profile-panel {
  background: var(--surface);
}

.feed-panel {
  border-right: 1px solid var(--border);
}

.workspace[data-active-panel="feed"] .feed-panel {
  border-right: 0;
}

.workspace[data-active-panel="feed"] .post-list {
  max-width: 1240px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
}

.workspace[data-active-panel="feed"] .empty-state {
  grid-column: 1 / -1;
}

.profile-panel {
  border-left: 1px solid var(--border);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading.compact {
  margin-bottom: 20px;
}

.panel-heading h1,
.panel-heading h2,
.reader-empty h2,
.modal h2,
.reader-content h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.1;
}

.panel-heading h1 {
  font-size: 30px;
}

.panel-heading h2,
.reader-empty h2,
.modal h2 {
  font-size: 22px;
}

.panel-heading p,
.reader-empty p {
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.5;
  font-size: 14px;
}

.post-list {
  display: grid;
  gap: 12px;
}

.post-card {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
  text-align: left;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.post-card:hover,
.post-card.is-selected {
  border-color: rgba(79, 127, 120, 0.55);
  box-shadow: 0 14px 28px rgba(17, 24, 39, 0.08);
}

.post-card:hover {
  transform: translateY(-1px);
}

.post-card button {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  text-align: left;
}

.post-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  background: linear-gradient(135deg, #e7f0ed, #f8efe1);
  object-fit: cover;
}

.post-card h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.post-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-stats,
.reader-meta,
.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.reader-panel {
  background: #fff;
}

.reader-empty {
  height: calc(100vh - 48px);
  display: grid;
  place-content: center;
  text-align: center;
}

.reader-content {
  max-width: 780px;
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

.reader-cover-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

.reader-cover-wrap img {
  width: 100%;
  display: block;
  aspect-ratio: 16 / 8;
  object-fit: cover;
}

.reader-content h2 {
  font-size: clamp(28px, 4vw, 46px);
  max-width: 12ch;
}

.reader-body {
  white-space: pre-wrap;
  line-height: 1.85;
  color: #263238;
  font-size: 16px;
}

.reader-actions {
  display: flex;
  gap: 10px;
}

.comments {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  display: grid;
  gap: 14px;
}

.comments-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.comments h3 {
  margin: 0;
  font-size: 18px;
}

.comment-form,
.profile-form,
.composer-form,
#authForm {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  line-height: 1.4;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 127, 120, 0.14);
}

.comment-list {
  display: grid;
  gap: 10px;
}

.comment-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
}

.comment-item p {
  margin: 8px 0 0;
  line-height: 1.6;
}

.profile-form {
  align-content: start;
}

.security-panel,
.admin-panel {
  margin-top: 26px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
  display: grid;
  gap: 14px;
}

.inline-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.auth-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-tabs button {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 36px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 10px;
  font-weight: 800;
}

.auth-tabs button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.admin-user-list {
  display: grid;
  gap: 10px;
}

.admin-user-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.admin-user-item strong,
.admin-user-item span,
.admin-user-item small {
  display: block;
}

.admin-user-item span,
.admin-user-item small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.admin-user-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.admin-user-actions .ghost-button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 12px;
}

.avatar-uploader,
.image-uploader {
  border: 1px dashed #b8c6c2;
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
  color: var(--muted);
  place-items: center;
  text-align: center;
}

.avatar-uploader input,
.image-uploader input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.avatar-uploader {
  min-height: 128px;
}

.avatar-uploader .avatar-preview {
  width: 66px;
  height: 66px;
  font-size: 22px;
}

.image-uploader {
  min-height: 150px;
}

.image-uploader img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.38);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}

.modal {
  width: min(100%, 420px);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  position: relative;
  display: grid;
  gap: 18px;
}

.modal.wide {
  width: min(100%, 720px);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  background: var(--text);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 30;
  line-height: 1.5;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px;
  background: #fff;
  color: var(--muted);
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  .workspace[data-active-panel="reader"] {
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  }

  .workspace[data-active-panel="settings"] {
    grid-template-columns: minmax(300px, 420px) minmax(340px, 1fr);
  }

  .workspace[data-active-panel="settings"] .profile-panel {
    grid-column: auto;
    border-left: 1px solid var(--border);
    border-top: 0;
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 14px;
  }

  .brand {
    justify-content: space-between;
  }

  .nav-list,
  .sidebar-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-box {
    margin-top: 0;
  }

  .workspace {
    display: block;
  }

  .feed-panel,
  .reader-panel,
  .profile-panel {
    padding: 18px;
    border: 0;
  }

  .reader-content h2 {
    max-width: none;
    font-size: 30px;
  }
}

@media (max-width: 520px) {
  .panel-heading {
    align-items: center;
  }

  .panel-heading h1 {
    font-size: 26px;
  }

  .nav-list,
  .sidebar-actions {
    grid-template-columns: 1fr;
  }

  .reader-actions {
    display: grid;
  }

  .admin-user-actions {
    grid-template-columns: 1fr;
  }
}
