:root {
  --bg: #f6f4ef;
  --paper: #ffffff;
  --ink: #2d3748;
  --muted: #8a8f98;
  --accent: #e07a5f;
  --accent-2: #3d405b;
  --line: #e6e1d8;
  --ok: #3a9d6a;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(45, 55, 72, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Верхняя панель --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.logo { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }

.tabs { display: flex; gap: 8px; }

.tab {
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.tab:hover { transform: translateY(-1px); }
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(224, 122, 95, 0.35);
}

.date-display {
  margin-left: auto;
  font-size: 14px;
  color: var(--muted);
}

/* --- Панели --- */
.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
}
.tab-panel.active { display: flex; }

/* --- Кнопки и поля --- */
.btn {
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  width: 100%;
  margin-bottom: 8px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.05); color: #fff; }
.btn.danger { background: #fff5f5; border-color: #f5c6c6; color: #c0392b; }
.btn.small { width: auto; padding: 5px 10px; font-size: 12px; margin: 0; }

.field {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 10px;
  background: var(--paper);
}

/* --- Записи --- */
#panel-notes { flex-direction: row; }

.sidebar {
  width: 280px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  flex-shrink: 0;
}

.note-list { list-style: none; padding: 0; margin: 16px 0 0; }
.note-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.12s;
  background: var(--bg);
}
.note-list li:hover { border-color: var(--accent); transform: translateX(2px); }
.note-list li.active { border-color: var(--accent); background: #fff4f0; }
.note-list .nl-title { font-weight: 600; font-size: 14px; }
.note-list .nl-date { font-size: 11px; color: var(--muted); margin-top: 3px; }

.editor { flex: 1; padding: 26px; overflow-y: auto; }

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}
.empty-icon { font-size: 56px; margin-bottom: 12px; }

.editor-form {
  max-width: 860px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }

.note-title {
  width: 100%;
  border: none;
  border-bottom: 2px solid var(--line);
  font-size: 26px;
  font-weight: 700;
  padding: 6px 0 10px;
  outline: none;
  background: transparent;
}
.note-title:focus { border-color: var(--accent); }

.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0;
  font-size: 13px;
  color: var(--muted);
}

.note-body {
  width: 100%;
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.65;
  resize: vertical;
  outline: none;
  font-family: inherit;
}
.note-body:focus { border-color: var(--accent); }

.save-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
}
.save-row .btn { width: auto; margin: 0; }
.save-actions { display: flex; gap: 8px; }
.save-status { font-size: 13px; color: var(--ok); }
.save-status.warn { color: var(--accent); font-weight: 600; }

/* --- Рисование --- */
#panel-draw { flex-direction: row; }

.toolbar {
  width: 260px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  flex-shrink: 0;
}

.tool-group { margin-bottom: 20px; }
.tool-group label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.tool-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tool {
  width: 44px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
  font-size: 17px;
  transition: all 0.12s;
}
.tool:hover { border-color: var(--accent); }
.tool.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  background: var(--paper);
}

.color-presets {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.color-presets span {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.color-presets span:hover { transform: scale(1.15); }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(-45deg, #eee 25%, transparent 25%) 0 10px/20px 20px,
    linear-gradient(45deg, transparent 75%, #eee 75%) 10px -10px/20px 20px,
    linear-gradient(-45deg, transparent 75%, #eee 75%) -10px 0/20px 20px;
}

#drawCanvas {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: crosshair;
  touch-action: none;
}

.saved-drawings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.saved-drawings img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.saved-drawings .empty { font-size: 12px; color: var(--muted); grid-column: 1/-1; }

/* --- Таблицы --- */
#panel-table { flex-direction: row; }

.table-area { flex: 1; padding: 24px; overflow: auto; }
.table-list { list-style: none; padding: 0; margin: 0; }
.table-list li {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
  background: var(--bg);
}
.table-list li:hover,
.table-list li.active { border-color: var(--accent); background: #fff4f0; }

.table-scroll { overflow-x: auto; }

.grid {
  border-collapse: collapse;
  min-width: 100%;
  background: var(--paper);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  overflow: hidden;
}
.grid td {
  border: 1px solid var(--line);
  min-width: 120px;
  height: 42px;
  padding: 0;
}
.grid tr:first-child td { background: var(--accent-2); color: #fff; font-weight: 600; }
.grid td input {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  padding: 8px 10px;
  font-size: 14px;
  background: transparent;
  font-family: inherit;
}
.grid tr:first-child td input { color: #fff; font-weight: 600; }
.grid td:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }

.hint { font-size: 13px; color: var(--muted); margin-top: 10px; }

@media (max-width: 760px) {
  .tab-panel.active { flex-direction: column; }
  .sidebar, .toolbar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
  .date-display { display: none; }
}
