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

:root {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --border: #e0dfd8;
  --text: #1a1a1a;
  --text-2: #5a5a5a;
  --text-3: #8a8a8a;
  --accent: #2c5f2e;
  --accent-light: #e8f0e8;
  --accent-hover: #234d25;
  --danger: #c0392b;
  --danger-light: #fdf0ee;
  --warning: #7d5a00;
  --warning-light: #fdf6e3;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Consolas', monospace;
  --jovan-color: #1a4a7a;
  --jovan-bg: #eef3fa;
  --aleksa-color: #0d7a5f;
  --aleksa-bg: #e8f5f1;
}

html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }

/* ─── Dark mode ──────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #111113;
  --surface: #1c1c1f;
  --surface-2: #242428;
  --border: #2e2e33;
  --text: #e8e8ea;
  --text-2: #9a9aa8;
  --text-3: #5a5a68;
  --accent: #4caf50;
  --accent-light: #162016;
  --accent-hover: #66bb6a;
  --danger: #e57373;
  --danger-light: #2a1414;
  --warning: #ffb74d;
  --warning-light: #261a08;
  --jovan-color: #64b5f6;
  --jovan-bg: #0d1a2e;
  --aleksa-color: #4db89a;
  --aleksa-bg: #0a1f1a;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.5);
}
[data-theme="dark"] .login-form { border-color: var(--border); }
[data-theme="dark"] .search-highlight { background: #5a4a00; color: #ffe082; }

/* ─── Login ─────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-container { width: 100%; max-width: 360px; padding: 1.5rem; }
.login-brand {
  font-size: 2.2rem; font-weight: 700; letter-spacing: -1px;
  color: var(--accent); text-align: center; margin-bottom: 2rem;
}
.login-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow-md);
}

/* ─── Forms ──────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-2); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="url"],
textarea, select {
  width: 100%; padding: 0.5rem 0.7rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font); font-size: 0.95rem; color: var(--text);
  background: var(--surface); transition: border-color 0.15s;
}
.form-group input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }

/* ─── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.45rem 1rem; border-radius: var(--radius);
  border: 1px solid transparent; font-family: var(--font);
  font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: all 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger-light); color: var(--danger); border-color: #e8b4ae; }
.btn-danger:hover:not(:disabled) { background: #f9e0dc; }
.btn-ghost { background: transparent; color: var(--text-3); border-color: transparent; padding: 0.3rem 0.6rem; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-full { width: 100%; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ─── Messages ───────────────────────────────────────── */
.error-msg { color: var(--danger); font-size: 0.85rem; padding: 0.5rem 0.7rem; background: var(--danger-light); border-radius: var(--radius); margin-top: 0.5rem; }
.success-msg { color: #1a6a2e; font-size: 0.85rem; padding: 0.5rem 0.7rem; background: var(--accent-light); border-radius: var(--radius); margin-top: 0.5rem; }
.info-msg { color: var(--text-2); font-size: 0.85rem; padding: 0.5rem 0.7rem; background: var(--surface-2); border-radius: var(--radius); }

/* ─── App Layout ─────────────────────────────────────── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 1.5rem; display: flex; align-items: center; justify-content: space-between;
  height: 52px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow);
}
.app-brand { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.5px; color: var(--accent); }
.header-user { display: flex; align-items: center; gap: 0.75rem; }
.header-user .username { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; padding: 0.3rem 0.55rem; font-size: 0.95rem; line-height: 1;
  color: var(--text-2); transition: background 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--surface-2); border-color: var(--text-3); }

/* ─── Search ─────────────────────────────────────────── */
.header-search { position: relative; flex: 1; max-width: 360px; margin: 0 1.5rem; }
.header-search input {
  width: 100%; padding: 0.38rem 0.75rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-family: var(--font); font-size: 0.88rem;
  background: var(--surface-2); color: var(--text); transition: border-color 0.15s;
}
.header-search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.search-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  z-index: 150; max-height: 380px; overflow-y: auto;
}
.search-result {
  padding: 0.6rem 0.85rem; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--surface-2); }
.search-result-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 2px; }
.search-result-date { font-size: 0.72rem; color: var(--text-3); font-weight: 600; }
.search-result-user { font-size: 0.68rem; font-weight: 700; padding: 1px 6px; border-radius: 20px; }
.search-result-user.jovan { color: var(--jovan-color); background: var(--jovan-bg); }
.search-result-user.aleksa { color: var(--aleksa-color); background: var(--aleksa-bg); }
.search-result-title { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.search-result-excerpt { font-size: 0.78rem; color: var(--text-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-highlight { background: #fff3b0; border-radius: 2px; }
.search-empty { padding: 1rem; text-align: center; color: var(--text-3); font-size: 0.85rem; }

.app-body { flex: 1; padding: 1.25rem; max-width: 1400px; margin: 0 auto; width: 100%; }

/* ─── Calendar ───────────────────────────────────────── */
.calendar-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.calendar-nav {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.9rem;
}
.calendar-nav h2 { font-size: 1rem; font-weight: 700; color: var(--text); }
.calendar-nav .btn { padding: 0.25rem 0.6rem; }
.calendar-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.6rem; }
@media (max-width: 900px) { .calendar-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .calendar-grid { grid-template-columns: repeat(2, 1fr); } }

.calendar-month { }
.calendar-month-name {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 0.35rem;
}
.calendar-month-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.cal-day-header { font-size: 0.6rem; color: var(--text-3); text-align: center; font-weight: 600; padding: 2px 0; }
.cal-day {
  font-size: 0.72rem; text-align: center; padding: 3px 1px;
  border-radius: 3px; cursor: pointer; transition: background 0.1s; color: var(--text);
  min-width: 0;
}
.cal-day:hover:not(.cal-disabled):not(.cal-selected) { background: var(--surface-2); }
.cal-day.cal-disabled { color: var(--text-3); cursor: default; opacity: 0.4; }
.cal-day.cal-today { font-weight: 700; color: var(--accent); }
.cal-day.cal-selected { background: var(--accent); color: #fff; border-radius: 3px; }
.cal-day.cal-has-note { position: relative; }
.cal-day.cal-has-note::after {
  content: ''; position: absolute; bottom: 1px; left: 50%; transform: translateX(-50%);
  width: 3px; height: 3px; border-radius: 50%; background: var(--accent);
}
.cal-day.cal-selected::after { background: #fff; }
.cal-empty { min-width: 0; }

/* ─── Middle Section ─────────────────────────────────── */
.middle-section {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem;
}
@media (max-width: 768px) { .middle-section { grid-template-columns: 1fr; } }

/* ─── Week View ──────────────────────────────────────── */
.week-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.week-section h3 { font-size: 0.85rem; font-weight: 700; color: var(--text-2); margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.week-days-header {
  display: grid; grid-template-columns: 90px repeat(7, 1fr);
  gap: 4px; margin-bottom: 4px;
}
.week-day-label { font-size: 0.68rem; font-weight: 600; text-align: center; color: var(--text-3); padding: 2px; }
.week-day-label.is-selected { color: var(--accent); font-weight: 700; }
.week-row { display: grid; grid-template-columns: 90px repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.week-user-label {
  font-size: 0.72rem; font-weight: 700; display: flex; align-items: center;
  padding: 2px 4px; border-radius: 3px;
}
.week-user-label.jovan { color: var(--jovan-color); background: var(--jovan-bg); }
.week-user-label.aleksa { color: var(--aleksa-color); background: var(--aleksa-bg); }
.week-cell {
  font-size: 0.65rem; padding: 4px; border-radius: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; transition: all 0.1s; overflow: hidden;
  min-height: 36px; display: flex; flex-direction: column; gap: 2px;
}
.week-cell:hover { border-color: var(--accent); background: var(--accent-light); }
.week-cell.is-disabled { opacity: 0.3; cursor: default; }
.week-cell.is-selected { border-color: var(--accent); background: var(--accent-light); }
.week-cell-title { font-weight: 600; color: var(--text); line-height: 1.2; }
.week-cell-desc { color: var(--text-3); line-height: 1.2; }
.week-cell.has-note { border-left: 2px solid var(--accent); }
.week-loading { font-size: 0.8rem; color: var(--text-3); padding: 0.5rem 0; }

/* ─── Note Form ──────────────────────────────────────── */
.note-form-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.form-date-label {
  font-size: 0.72rem; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.25rem;
}
.form-date-value { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 0.9rem; }

.links-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0.5rem; }
.link-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: center; }
.link-row input { font-size: 0.82rem; }
.add-link-btn { font-size: 0.78rem; color: var(--accent); cursor: pointer; background: none; border: none; padding: 0; font-family: var(--font); }
.add-link-btn:hover { text-decoration: underline; }

.image-preview-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.img-thumb {
  position: relative; width: 60px; height: 60px;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-thumb .remove-img {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.6);
  color: #fff; border: none; border-radius: 3px; font-size: 0.65rem;
  cursor: pointer; padding: 1px 4px; line-height: 1.4;
}
.form-actions { display: flex; justify-content: flex-end; margin-top: 0.75rem; }
.form-blocked-msg { font-size: 0.82rem; color: var(--text-3); font-style: italic; margin-top: 0.5rem; }

/* ─── Notes List ─────────────────────────────────────── */
.notes-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.notes-section-header {
  display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 0.9rem;
}
.notes-section-header h3 { font-size: 0.85rem; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.notes-date-badge {
  font-size: 0.78rem; font-weight: 600; color: var(--text-3);
}

.notes-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .notes-columns { grid-template-columns: 1fr; } }

.user-column-header {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 4px 8px; border-radius: 4px;
  margin-bottom: 0.6rem; display: inline-block;
}
.user-column-header.jovan { color: var(--jovan-color); background: var(--jovan-bg); }
.user-column-header.aleksa { color: var(--aleksa-color); background: var(--aleksa-bg); }

.note-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.75rem; margin-bottom: 0.75rem; background: var(--surface);
  transition: box-shadow 0.15s;
}
.note-card:hover { box-shadow: var(--shadow-md); }
.note-card.jovan { border-left: 3px solid var(--jovan-color); }
.note-card.aleksa { border-left: 3px solid var(--aleksa-color); }

.note-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.3rem; }
.note-description { font-size: 0.88rem; color: var(--text-2); white-space: pre-wrap; word-break: break-word; }
.note-meta {
  font-size: 0.72rem; color: var(--text-3); margin-top: 0.4rem;
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.edited-badge { font-size: 0.68rem; color: var(--warning); background: var(--warning-light); padding: 1px 6px; border-radius: 20px; }

.note-images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 0.6rem; }
.note-img {
  width: 80px; height: 80px; object-fit: cover;
  border-radius: var(--radius); border: 1px solid var(--border); cursor: pointer;
}
.note-links { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 3px; }
.note-link { font-size: 0.82rem; color: var(--accent); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-link:hover { text-decoration: underline; }

.note-actions { display: flex; gap: 0.4rem; margin-top: 0.6rem; flex-wrap: wrap; }

/* ─── Comments ───────────────────────────────────────── */
.comments-toggle {
  font-size: 0.78rem; color: var(--text-3); cursor: pointer;
  background: none; border: none; font-family: var(--font); padding: 0;
  margin-top: 0.5rem; display: block;
}
.comments-toggle:hover { color: var(--accent); }

.comments-area { margin-top: 0.6rem; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.comment-item {
  padding: 0.5rem 0.6rem; border-radius: var(--radius);
  background: var(--surface-2); margin-bottom: 0.5rem;
}
.comment-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; flex-wrap: wrap; }
.comment-author { font-size: 0.75rem; font-weight: 700; }
.comment-author.jovan { color: var(--jovan-color); }
.comment-author.aleksa { color: var(--aleksa-color); }
.comment-time { font-size: 0.68rem; color: var(--text-3); }
.comment-text { font-size: 0.85rem; white-space: pre-wrap; word-break: break-word; }
.comment-images { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 0.4rem; }
.comment-img { width: 60px; height: 60px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); cursor: pointer; }
.comment-actions { display: flex; gap: 0.3rem; margin-top: 0.4rem; }

.comment-form { margin-top: 0.6rem; }
.comment-form textarea { min-height: 56px; font-size: 0.85rem; }
.comment-form-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }

/* ─── Edit overlay ───────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 560px; max-height: 90vh;
  overflow-y: auto; padding: 1.25rem; box-shadow: var(--shadow-md);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }

/* ─── Lightbox ───────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 300; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius); }

/* ─── Empty state ────────────────────────────────────── */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-3); font-size: 0.88rem; }

/* ─── Misc ───────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 0.75rem 0; }
[hidden] { display: none !important; }
