:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --surface-2: #f4f2ec;
  --border: #e8e5dc;
  --text: #1f1e1d;
  --muted: #6f6d66;
  --accent: #c96442;
  --accent-hover: #b4553a;
  --accent-soft: #f7e6de;
  --accent-text: #ffffff;
  --ok: #3f7d58;
  --ok-soft: #e2f0e7;
  --danger: #b3402a;
  --danger-soft: #f8e3de;
  --shadow: 0 1px 2px rgba(31, 30, 29, .05), 0 4px 16px rgba(31, 30, 29, .05);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1e1d;
    --surface: #2a2927;
    --surface-2: #252422;
    --border: #3a3835;
    --text: #f0eee6;
    --muted: #a3a097;
    --accent: #d97757;
    --accent-hover: #e48a6d;
    --accent-soft: #3d2b24;
    --accent-text: #1f1e1d;
    --ok: #6fb58a;
    --ok-soft: #22332a;
    --danger: #e0826c;
    --danger-soft: #3a2621;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

:root[data-theme="dark"] {
  --bg: #1f1e1d;
  --surface: #2a2927;
  --surface-2: #252422;
  --border: #3a3835;
  --text: #f0eee6;
  --muted: #a3a097;
  --accent: #d97757;
  --accent-hover: #e48a6d;
  --accent-soft: #3d2b24;
  --accent-text: #1f1e1d;
  --ok: #6fb58a;
  --ok-soft: #22332a;
  --danger: #e0826c;
  --danger-soft: #3a2621;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 21px; }
h3 { font-size: 17px; margin-top: 1.6em; }
p { margin: 0 0 .8em; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; margin: 20px 0 40px; }
[hidden] { display: none !important; }

/* Каркас */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
  padding: 22px 16px; border-right: 1px solid var(--border); background: var(--surface-2);
}
.brand { display: flex; align-items: center; gap: 10px; font: 500 21px/1 var(--serif); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--accent); display: inline-block; }
.project-switch { display: grid; gap: 4px; }
.nav { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--text);
}
.nav-item:hover { background: var(--border); }
.nav-item.is-active { background: var(--surface); box-shadow: var(--shadow); font-weight: 500; }
.nav-item.is-soon { color: var(--muted); cursor: default; }
.nav-item.is-soon:hover { background: transparent; }
.soon { font-size: 11px; background: var(--border); border-radius: 99px; padding: 1px 8px; }
.badge { background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 600; min-width: 22px; text-align: center; border-radius: 99px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 4px; }
.foot-actions { display: flex; gap: 14px; }
.foot-actions form { margin: 0; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

.main { padding: 36px clamp(16px, 4vw, 48px) 60px; max-width: 1080px; width: 100%; }
.page-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head p { max-width: 62ch; margin: 0; }

/* Элементы форм */
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 96px; resize: vertical; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 16px; text-decoration: none; display: inline-block;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.block { padding: 24px; margin-bottom: 20px; }
.empty { padding: 40px; text-align: center; }
.alert { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }

.inline-form { display: flex; gap: 10px; max-width: 560px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 720px; }
.grid-form .wide { grid-column: 1 / -1; }

/* Фильтры и журнал */
.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 18px; }
.filters select, .filters input[type="date"] { width: auto; min-width: 150px; }

.day { font: 500 13px var(--font); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 8px; }
.journal { display: grid; gap: 8px; }
.row {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: start; text-align: left;
  width: 100%; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  transition: border-color .15s, box-shadow .15s;
}
.row:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.row-time { color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.row-title { font-weight: 500; }
.row-sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.row-note { font-size: 13px; margin-top: 6px; color: var(--text); }
.row-note b { font-weight: 500; }

.pill { display: inline-block; font-size: 12px; font-weight: 500; border-radius: 99px; padding: 2px 10px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill-warn { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* Панель деталей */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .28); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); z-index: 21; overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: -8px 0 32px rgba(0, 0, 0, .12);
  padding: 26px 26px 40px;
}
.drawer-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.drawer-close { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.obj { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.obj-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.obj-name { font-weight: 500; overflow-wrap: anywhere; }
.change { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; padding: 5px 0; border-top: 1px dashed var(--border); font-size: 14px; }
.change:first-of-type { border-top: 0; }
.change-field { color: var(--muted); }
.old { color: var(--danger); text-decoration: line-through; overflow-wrap: anywhere; }
.new { color: var(--ok); overflow-wrap: anywhere; }
.arrow { color: var(--muted); margin: 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border-radius: 6px; padding: 1px 8px; font-size: 13px; overflow-wrap: anywhere; }
.chip-add { background: var(--ok-soft); color: var(--ok); }
.chip-del { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.comment { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.comment-meta { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.comment-form { display: grid; gap: 10px; margin-top: 14px; }

/* Настройки */
.accounts { display: grid; gap: 10px; margin-bottom: 8px; }
.account { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface-2); }
.account-actions { display: flex; gap: 8px; }

/* Уведомления */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); border-radius: 10px; padding: 10px 16px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.is-error { background: var(--danger); color: #fff; }

/* Вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(400px, 100%); padding: 32px; display: grid; gap: 14px; }
.auth-card h1 { margin: 0; }
.auth-card .brand { margin-bottom: 8px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { display: flex; flex-wrap: wrap; order: 3; width: 100%; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .project-switch label { display: none; }
  .grid-form { grid-template-columns: 1fr; }
  .row { grid-template-columns: 44px minmax(0, 1fr); }
  .row-side { grid-column: 2; }
  .change { grid-template-columns: 1fr; gap: 2px; }
}
