*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  resize: none;
}

.material-icons-outlined {
  font-size: 24px;
  vertical-align: middle;
}

/* ── Layout ── */

.app {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  min-height: 100vh;
}

.app.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

.app.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* ── Header ── */

.header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header__left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header__logo-icon {
  color: var(--color-peach, #fbbc04);
  font-size: 28px;
}

.header__title {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 400;
  letter-spacing: -0.25px;
}

.header__search {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 48px;
  transition: background 0.2s, box-shadow 0.2s;
}

.header__search:focus-within {
  background: var(--color-bg);
  box-shadow: 0 1px 3px var(--color-shadow), 0 4px 8px var(--color-shadow);
}

.header__search-icon {
  color: var(--color-text-secondary);
  margin-right: 8px;
}

.header__search-input {
  flex: 1;
  height: 100%;
}

.header__search-clear {
  opacity: 0.7;
}

.header__right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.header__actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* ── Icon button ── */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--color-surface-hover);
}

.icon-btn--small {
  width: 36px;
  height: 36px;
}

/* ── Sidebar ── */

.sidebar {
  grid-area: sidebar;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  padding: 8px 0;
  overflow-y: auto;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px 0 16px;
  height: 48px;
  border-radius: 0 24px 24px 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
  transition: background 0.15s;
  width: 100%;
  text-align: left;
}

.sidebar__item:hover {
  background: var(--color-surface-hover);
}

.sidebar__item--active {
  background: #feefc3;
  color: var(--color-text);
}

[data-theme="dark"] .sidebar__item--active {
  background: #41331c;
}

.sidebar__item .material-icons-outlined {
  font-size: 20px;
  color: var(--color-text-secondary);
}

.sidebar__item--active .material-icons-outlined {
  color: var(--color-text);
}

.sidebar__divider {
  height: 1px;
  background: var(--color-border);
  margin: 8px 16px;
}

.sidebar__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.sidebar__folders {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__folder {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px 0 16px;
  height: 48px;
  border-radius: 0 24px 24px 0;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
  width: 100%;
  text-align: left;
  position: relative;
}

.sidebar__folder:hover {
  background: var(--color-surface-hover);
}

.sidebar__folder--active {
  background: #feefc3;
}

[data-theme="dark"] .sidebar__folder--active {
  background: #41331c;
}

.sidebar__folder .material-icons-outlined {
  font-size: 20px;
  color: var(--color-text-secondary);
}

.sidebar__folder-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.sidebar__folder-delete {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar__folder-delete .material-icons-outlined {
  font-size: 18px;
}

.sidebar__folder:hover .sidebar__folder-delete {
  display: inline-flex;
}

.sidebar__folder:hover .sidebar__folder-count {
  display: none;
}

/* ── Main ── */

.main {
  grid-area: main;
  padding: 32px 16px 64px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── Compose ── */

.compose {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 2px var(--color-shadow);
  padding: 16px 16px 8px;
  margin-bottom: 32px;
  transition: box-shadow 0.2s;
}

.compose--expanded {
  box-shadow: 0 1px 3px var(--color-shadow), 0 4px 8px var(--color-shadow);
}

.compose__title {
  width: 100%;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.compose__body {
  width: 100%;
  font-size: 0.875rem;
  line-height: 1.5;
  min-height: 24px;
}

.compose__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.compose__colors {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.compose__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.compose__folder-select {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 0.8125rem;
  cursor: pointer;
}

/* ── Buttons ── */

.btn {
  padding: 8px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
}

.btn--text {
  color: var(--color-text);
}

.btn--text:hover {
  background: var(--color-surface-hover);
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--color-primary-hover);
}

.btn--primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Color picker ── */

.color-picker {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.color-picker__btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}

.color-picker__btn:hover {
  transform: scale(1.1);
}

.color-picker__btn--selected {
  border-color: var(--color-text-secondary);
}

.color-picker__btn--default {
  background: var(--note-default);
  border: 1px solid var(--color-border);
}

.color-picker__btn--coral { background: var(--note-coral); }
.color-picker__btn--peach { background: var(--note-peach); }
.color-picker__btn--sand { background: var(--note-sand); }
.color-picker__btn--mint { background: var(--note-mint); }
.color-picker__btn--sage { background: var(--note-sage); }
.color-picker__btn--fog { background: var(--note-fog); }
.color-picker__btn--storm { background: var(--note-storm); }
.color-picker__btn--dusk { background: var(--note-dusk); }
.color-picker__btn--blossom { background: var(--note-blossom); }
.color-picker__btn--clay { background: var(--note-clay); }
.color-picker__btn--chalk { background: var(--note-chalk); }

/* ── Notes grid ── */

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  align-items: start;
}

.note-card {
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  position: relative;
  transition: box-shadow 0.2s;
  border: 1px solid transparent;
  word-break: break-word;
}

.note-card:hover {
  box-shadow: 0 1px 3px var(--color-shadow), 0 4px 8px var(--color-shadow);
}

.note-card--default { background: var(--note-default); border-color: var(--color-border); }
.note-card--coral { background: var(--note-coral); }
.note-card--peach { background: var(--note-peach); }
.note-card--sand { background: var(--note-sand); }
.note-card--mint { background: var(--note-mint); }
.note-card--sage { background: var(--note-sage); }
.note-card--fog { background: var(--note-fog); }
.note-card--storm { background: var(--note-storm); }
.note-card--dusk { background: var(--note-dusk); }
.note-card--blossom { background: var(--note-blossom); }
.note-card--clay { background: var(--note-clay); }
.note-card--chalk { background: var(--note-chalk); }

.note-card__title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.note-card__body {
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--color-text);
  display: -webkit-box;
  -webkit-line-clamp: 12;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.note-card__folder {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.note-card__folder .material-icons-outlined {
  font-size: 14px;
}

.note-card__actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  gap: 2px;
}

.note-card:hover .note-card__actions {
  display: flex;
}

.note-card__action {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.6);
  transition: background 0.15s;
}

[data-theme="dark"] .note-card__action {
  background: rgba(0, 0, 0, 0.3);
}

.note-card__action:hover {
  background: rgba(255, 255, 255, 0.9);
}

.note-card__action .material-icons-outlined {
  font-size: 18px;
}

.note-card--pinned::before {
  content: '';
  position: absolute;
  top: 0;
  right: 16px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid var(--color-text-secondary);
  opacity: 0.4;
}

/* ── Empty state ── */

.empty-state {
  text-align: center;
  padding: 64px 16px;
  color: var(--color-text-secondary);
}

.empty-state__icon {
  font-size: 64px;
  opacity: 0.4;
  margin-bottom: 16px;
}

/* ── Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  z-index: 200;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px var(--color-shadow-heavy);
  width: 90%;
  max-width: 600px;
  padding: 16px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 12px;
}

.modal__body {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.6;
  min-height: 200px;
  overflow-y: auto;
}

.modal__footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.modal__colors {
  flex: 1;
}

.modal__folder-select {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 0.8125rem;
  cursor: pointer;
}

.modal__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ── Dialog ── */

.dialog {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px var(--color-shadow-heavy);
  width: 90%;
  max-width: 400px;
  padding: 24px;
}

.dialog__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 16px;
}

.dialog__input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-size: 1rem;
}

.dialog__input:focus {
  border-color: var(--color-primary);
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Toast ── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  z-index: 300;
  animation: toast-in 0.3s ease;
}

.toast[hidden] {
  display: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Login ── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  padding: 24px;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px var(--color-shadow), 0 8px 24px var(--color-shadow);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}

.login-card__header {
  text-align: center;
  margin-bottom: 32px;
}

.login-card__icon {
  font-size: 48px;
  color: #fbbc04;
}

.login-card__title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  margin-top: 8px;
}

.login-card__subtitle {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  margin-top: 4px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-form__label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.login-form__input {
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 1rem;
  color: var(--color-text);
}

.login-form__input:focus {
  border-color: var(--color-primary);
}

.login-form__error {
  color: var(--color-danger);
  font-size: 0.8125rem;
}

.login-form__error[hidden] {
  display: none;
}

.login-form__submit {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
}

/* ── Account (правый верхний угол) ── */

.header__account {
  display: flex;
  align-items: center;
  min-width: 0;
}

.header__account[hidden] {
  display: none;
}

.header__account-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 16px 0 6px;
  background: var(--color-surface);
  border-radius: 24px;
  min-width: 0;
  width: max-content;
  max-width: min(300px, 32vw);
  transition: background 0.2s, box-shadow 0.2s;
}

.header__account-pill:hover {
  background: var(--color-surface-hover);
}

.header__account-pill--admin {
  padding: 0 20px 0 14px;
  gap: 12px;
  min-width: 240px;
  max-width: min(400px, 42vw);
}

.header__account-pill[hidden] {
  display: none;
}

.header__account-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #1a73e8;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  user-select: none;
}

[data-theme="dark"] .header__account-avatar {
  background: #8ab4f8;
  color: #202124;
}

.header__account-icon {
  flex-shrink: 0;
  font-size: 24px !important;
  color: var(--color-text-secondary);
}

.header__account-name {
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}

.header__account-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
  background-color: transparent;
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  min-width: 140px;
  width: 0;
  height: 100%;
  padding: 0 28px 0 2px;
  line-height: 48px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='%235f6368'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  background-size: 16px;
}

.header__account-select option {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 500;
  padding: 10px 14px;
  line-height: 1.4;
}

[data-theme="dark"] .header__account-select {
  color: var(--color-text);
  color-scheme: dark;
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='%239aa0a6'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
}

[data-theme="dark"] .header__account-select option {
  background-color: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
}

.header__account-select:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Admin banner ── */

.admin-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #e8f0fe;
  color: #1a73e8;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  margin-bottom: 16px;
}

[data-theme="dark"] .admin-banner {
  background: #1e3a5f;
  color: #8ab4f8;
}

.admin-banner[hidden] {
  display: none;
}

.admin-banner .material-icons-outlined {
  font-size: 20px;
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .app {
    grid-template-columns: 0 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 90;
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
    box-shadow: 2px 0 8px var(--color-shadow);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .header__title {
    display: none;
  }

  .header__search {
    max-width: none;
  }

  .header__account-pill {
    max-width: min(260px, 55vw);
    padding-right: 12px;
  }

  .header__account-pill--admin {
    min-width: 200px;
    max-width: min(300px, 58vw);
  }

  .header__account-select {
    min-width: 120px;
    font-size: 0.9375rem;
  }

  .header__right {
    gap: 4px;
  }

  .main {
    padding: 16px 8px 48px;
  }

  .notes-grid {
    grid-template-columns: 1fr;
  }
}