
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #667085;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #c2415b;
  --sidebar: 300px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }

button, select { cursor: pointer; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 78px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--primary);
  color: #fff; font-weight: 800; font-size: 21px;
}
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .04em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.role-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.role-control select {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  background: #fff; color: var(--text);
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: calc(100vh - 78px);
}

.sidebar {
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #f8f9fb;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(16, 24, 40, .025);
}

.panel-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel h2 { margin: 0; font-size: 15px; }
.mini-actions { font-size: 12px; color: var(--muted); }

.link-btn { background: transparent; border: 0; padding: 0; color: var(--primary); }

.theme-list { display: grid; gap: 8px; }
.theme-item {
  display: grid;
  grid-template-columns: 18px 11px 1fr;
  align-items: start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.28;
}
.theme-item input { margin-top: 1px; }
.theme-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 3px; }

.field-label, .form-grid label > span {
  display: block; margin-bottom: 6px; font-weight: 650; font-size: 12.5px;
}

.full-width { width: 100%; }
.center-text { text-align: center; }
.hint { color: var(--muted); font-size: 11.5px; line-height: 1.4; margin: 8px 0 0; }
.muted-panel { background: #f7f8ff; color: var(--muted); }
.muted-panel strong { color: var(--text); font-size: 12.5px; }
.muted-panel p { font-size: 11.5px; line-height: 1.45; margin-bottom: 0; }

select, input, textarea {
  border: 1px solid #d0d5dd;
  border-radius: 9px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.10); }

.primary-btn, .secondary-btn, .danger-btn, .icon-btn {
  border: 0;
  border-radius: 9px;
  padding: 9px 12px;
  font-weight: 650;
}
.primary-btn { background: var(--primary); color: #fff; }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { background: #eef0f5; color: #344054; text-decoration: none; display: inline-block; margin-top: 8px; }
.secondary-btn.compact { margin-top: 0; padding: 8px 11px; }
.danger-btn { background: #fdecef; color: var(--danger); }
.icon-btn {
  width: 36px; height: 36px; padding: 0;
  display: grid; place-items: center;
  background: #eef0f5; color: #344054; font-size: 22px;
}

#syncStatus[data-state="ok"] { color: #08745d; font-weight: 700; }
#syncStatus[data-state="error"] { color: var(--danger); font-weight: 700; }
#syncBtn + #syncStatus { margin-bottom: 12px; }

.calendar-area { min-width: 0; padding: 20px 24px 28px; }
.calendar-toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 14px;
}
.month-nav { display: flex; gap: 7px; }
.calendar-toolbar h2 { margin: 0; font-size: 22px; text-transform: capitalize; }

.calendar-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #fafafa;
  border-bottom: 1px solid var(--line);
}
.weekday-row div {
  padding: 11px 9px;
  text-align: center;
  font-size: 11px;
  font-weight: 750;
  color: var(--muted);
  letter-spacing: .04em;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(118px, 1fr));
  min-height: calc(100vh - 190px);
}

.day-cell {
  min-width: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px;
  background: #fff;
  overflow: hidden;
}
.day-cell:nth-child(7n) { border-right: 0; }
.day-cell:nth-last-child(-n+7) { border-bottom: 0; }
.day-cell.outside { background: #fafafa; }
.day-cell.today { background: #fbfbff; box-shadow: inset 0 0 0 2px rgba(79,70,229,.26); }

.day-header { display: flex; justify-content: flex-end; margin-bottom: 5px; }
.day-number {
  width: 25px; height: 25px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; color: #475467;
}
.today .day-number { background: var(--primary); color: #fff; font-weight: 700; }
.outside .day-number { color: #b3b8c2; }

.events { display: grid; gap: 4px; }
.event-chip {
  border: 0;
  width: 100%;
  text-align: left;
  color: #fff;
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 10.5px;
  line-height: 1.18;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(16,24,40,.08);
}
.event-chip:hover { filter: brightness(.96); transform: translateY(-1px); }
.more-events { font-size: 10.5px; color: var(--muted); padding: 2px 4px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .48);
  display: grid; place-items: center;
  padding: 20px;
}
.hidden { display: none !important; }

.modal {
  width: min(680px, 100%);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 22px 60px rgba(15, 23, 42, .24);
  overflow: hidden;
}
.modal-header {
  padding: 20px 22px 12px;
  display: flex; justify-content: space-between; align-items: start;
}
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-header p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

#eventForm { padding: 8px 22px 22px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid label input, .form-grid label select, .form-grid label textarea { width: 100%; }
.span-2 { grid-column: span 2; }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.modal-actions .secondary-btn { margin-top: 0; }
.grow { flex: 1; }

.event-meta {
  margin-top: 14px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 22px; bottom: 22px;
  z-index: 200;
  max-width: 390px;
  background: #101828;
  color: #fff;
  border-radius: 10px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  font-size: 12px;
}

body.viewer-mode .editor-only { display: none !important; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .calendar-grid { min-height: 720px; }
  .theme-list { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 650px) {
  .topbar { padding: 0 14px; }
  .brand p { display: none; }
  .calendar-area { padding: 14px 10px 24px; overflow-x: auto; }
  .calendar-card { min-width: 760px; }
  .calendar-toolbar { min-width: 760px; }
  .theme-list { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}

/* Čisti prikaz za vdelavo: samo teme, razred in koledar */
body.embed-mode { background: #f4f8f6; }
.embed-mode .topbar,
.embed-mode .sidebar .editor-only,
.embed-mode .sidebar .muted-panel { display: none !important; }
.viewer-mode .topbar,
.viewer-mode .sidebar .editor-only,
.viewer-mode .sidebar .muted-panel { display: none !important; }
.embed-mode .layout {
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}
.embed-mode .sidebar { padding-top: 20px; }
.embed-mode .calendar-area { padding-top: 20px; }
.embed-mode .calendar-grid { min-height: calc(100vh - 130px); }

@media (max-width: 980px) {
  .embed-mode .layout { grid-template-columns: 1fr; }
  .embed-mode .sidebar {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    padding: 12px;
  }
  .embed-mode .sidebar .panel { margin: 0; }
}

@media (max-width: 650px) {
  .embed-mode .sidebar { grid-template-columns: 1fr; }
}

/* Osvežena vizualna podoba */
:root {
  --bg: #eef4f1;
  --surface: #ffffff;
  --text: #173c3a;
  --muted: #6a7d79;
  --line: #d7e5e0;
  --primary: #236b68;
  --primary-dark: #174c4b;
  --danger: #b84355;
  --sidebar: 286px;
  --shadow: 0 18px 45px rgba(23, 76, 75, .10);
}

body {
  background:
    radial-gradient(circle at 82% 0%, rgba(214,154,67,.12), transparent 28rem),
    linear-gradient(180deg, #f7faf8 0%, var(--bg) 100%);
}

.topbar {
  height: 86px;
  padding: 0 32px;
  color: #fff;
  border: 0;
  background: linear-gradient(120deg, #174c4b 0%, #236b68 58%, #3b8980 100%);
  box-shadow: 0 10px 28px rgba(23,76,75,.20);
}

.brand { gap: 14px; }
.brand-mark {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255,255,255,.72);
  border-radius: 14px;
  background: rgba(255,255,255,.14);
  box-shadow: 0 7px 18px rgba(0,0,0,.16);
  font-size: 24px;
}
.brand h1 { color: #fff; font-size: 22px; letter-spacing: .06em; }
.brand p { color: #d9eeea; font-size: 12px; }
.role-control { color: #eaf6f3; font-weight: 700; }
.role-control select {
  min-width: 132px;
  border-color: rgba(255,255,255,.65);
  background: #fff;
  color: var(--primary-dark);
  font-weight: 750;
}

.layout { min-height: calc(100vh - 86px); }
.sidebar {
  padding: 22px 18px;
  border-color: #d4e3de;
  background: rgba(245,249,247,.88);
}
.panel {
  margin-bottom: 16px;
  padding: 17px;
  border-color: #d9e7e2;
  border-radius: 16px;
  box-shadow: 0 7px 20px rgba(34,84,79,.055);
}
.panel h2 { color: var(--primary-dark); font-size: 16px; }
.theme-item { padding: 3px 0; color: #405653; }
.theme-item input { accent-color: var(--primary); }
.theme-dot { box-shadow: 0 0 0 3px rgba(35,107,104,.07); }
.muted-panel { background: #edf7f4; }

.primary-btn {
  background: linear-gradient(135deg, var(--primary), #328079);
  box-shadow: 0 7px 16px rgba(35,107,104,.20);
}
.primary-btn:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.secondary-btn { background: #edf3f1; color: #294d49; }
.icon-btn { border: 1px solid #d6e3df; background: #f3f7f5; color: var(--primary-dark); }

.calendar-area { padding: 24px 28px 34px; }
.calendar-toolbar {
  min-height: 58px;
  margin-bottom: 14px;
  padding: 0 4px;
}
.calendar-toolbar h2 {
  color: var(--primary-dark);
  font-size: clamp(24px, 2.3vw, 36px);
  font-weight: 800;
  letter-spacing: -.035em;
}
.month-nav { align-items: center; }
.month-nav .icon-btn { width: 42px; height: 42px; border-radius: 12px; font-size: 26px; }
.month-nav .secondary-btn { padding: 11px 15px; border-radius: 11px; font-weight: 750; }

.calendar-card {
  border-color: #cfdfda;
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.weekday-row {
  background: linear-gradient(180deg, #e8f3ef, #edf6f3);
  border-color: #cfe0db;
}
.weekday-row div {
  padding: 14px 9px;
  color: #37635f;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .09em;
}
.weekday-row div:nth-child(6), .weekday-row div:nth-child(7) {
  color: #9a6328;
  background: #fbf4ea;
}
.calendar-grid {
  grid-template-rows: repeat(6, minmax(132px, 1fr));
  min-height: calc(100vh - 215px);
  background: #f7faf9;
}
.day-cell {
  padding: 10px;
  border-color: #d7e5e0;
  transition: background .16s ease, box-shadow .16s ease;
}
.day-cell:nth-child(7n-1), .day-cell:nth-child(7n) { background: #fffaf4; }
.day-cell.outside { background: #f3f6f5; }
.day-cell:hover { background: #eef8f5; box-shadow: inset 0 0 0 2px #7db6ab; }
.day-header { justify-content: flex-start; }
.day-number {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  color: #244b48;
  font-size: 14px;
  font-weight: 850;
}
.today .day-number {
  background: linear-gradient(135deg, #d89539, #edb65c);
  box-shadow: 0 5px 12px rgba(190,123,35,.28);
}
.events { gap: 5px; }
.event-chip {
  border-left: 4px solid rgba(0,0,0,.18);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 750;
  box-shadow: 0 3px 8px rgba(33,66,63,.12);
  transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}
.event-chip:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(33,66,63,.18); }
.viewer-mode .event-chip.viewer-static {
  cursor: help;
}
.viewer-mode .event-chip.viewer-static:hover {
  filter: none;
  transform: none;
  box-shadow: 0 3px 8px rgba(33,66,63,.12);
}

/* Zaklenjeni iframe: filtri zgoraj, koledar uporablja vso razpoložljivo širino. */
.viewer-mode.embed-mode .layout {
  display: block;
  width: 100%;
}
.viewer-mode.embed-mode .sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 300px);
  gap: 14px;
  width: 100%;
  padding: 14px 20px;
  border-right: 0;
  border-bottom: 1px solid var(--line);
}
.viewer-mode.embed-mode .sidebar .panel { margin: 0; }
.viewer-mode.embed-mode .theme-list {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px 12px;
}
.viewer-mode.embed-mode .calendar-area {
  width: 100%;
  padding: 16px 20px 24px;
}
.viewer-mode.embed-mode .calendar-grid {
  min-height: 760px;
  grid-template-rows: repeat(6, minmax(126px, 1fr));
}
.viewer-mode.embed-mode .event-chip {
  white-space: normal;
  text-overflow: clip;
  font-size: 12px;
  line-height: 1.25;
}

@media (max-width: 980px) {
  .viewer-mode.embed-mode .sidebar { grid-template-columns: 1fr; }
  .viewer-mode.embed-mode .theme-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
  .viewer-mode.embed-mode .sidebar { padding: 8px; }
  .viewer-mode.embed-mode .calendar-area { padding: 8px 4px 18px; }
  .viewer-mode.embed-mode .event-chip { font-size: 8px; line-height: 1.12; }
  .viewer-mode.embed-mode .calendar-grid {
    min-height: 468px;
    grid-template-rows: repeat(6, minmax(78px, auto));
  }
}

/* Izboljšan telefonski prikaz zaklenjenega koledarja. */
@media (max-width: 650px) {
  .viewer-mode.embed-mode .sidebar {
    gap: 7px;
    padding: 7px;
  }
  .viewer-mode.embed-mode .sidebar .panel {
    padding: 10px;
    border-radius: 11px;
  }
  .viewer-mode.embed-mode .theme-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 7px;
  }
  .viewer-mode.embed-mode .theme-item {
    grid-template-columns: 15px 8px minmax(0, 1fr);
    gap: 4px;
    font-size: 9px;
    line-height: 1.15;
  }
  .viewer-mode.embed-mode .calendar-toolbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    min-width: 0;
    min-height: 46px;
    gap: 8px;
    margin-bottom: 5px;
  }
  .viewer-mode.embed-mode .calendar-toolbar h2 {
    justify-self: end;
    font-size: clamp(18px, 6vw, 25px);
    white-space: nowrap;
  }
  .viewer-mode.embed-mode .month-nav { gap: 3px; }
  .viewer-mode.embed-mode .month-nav .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 22px;
  }
  .viewer-mode.embed-mode .month-nav .secondary-btn {
    margin: 0;
    padding: 7px;
    font-size: 10px;
  }
  .viewer-mode.embed-mode .calendar-card {
    min-width: 0;
    width: 100%;
    border-radius: 11px;
  }
  .viewer-mode.embed-mode .weekday-row div {
    padding: 8px 0;
    font-size: 8px;
  }
  .viewer-mode.embed-mode .calendar-grid {
    grid-template-rows: repeat(6, minmax(86px, auto));
    min-height: 516px;
  }
  .viewer-mode.embed-mode .day-cell {
    min-height: 86px;
    padding: 3px 2px;
  }
  .viewer-mode.embed-mode .day-number {
    width: 25px;
    height: 25px;
    font-size: 12px;
  }
  .viewer-mode.embed-mode .event-chip {
    display: -webkit-box;
    min-height: 21px;
    padding: 3px 2px;
    overflow: hidden;
    font-size: 8px;
    line-height: 1.12;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

@media (max-width: 390px) {
  .viewer-mode.embed-mode .month-nav .secondary-btn { display: none; }
  .viewer-mode.embed-mode .calendar-toolbar h2 { font-size: 18px; }
  .viewer-mode.embed-mode .day-cell { min-height: 82px; }
  .viewer-mode.embed-mode .calendar-grid {
    grid-template-rows: repeat(6, minmax(82px, auto));
    min-height: 492px;
  }
}

.modal-backdrop { background: rgba(14,43,41,.58); backdrop-filter: blur(5px); }
.modal { border: 1px solid rgba(255,255,255,.7); border-radius: 22px; box-shadow: 0 28px 80px rgba(12,45,43,.28); }
.modal-header { padding: 24px 26px 14px; }
.modal-header h2 { color: var(--primary-dark); font-size: 24px; }
#eventForm { padding: 10px 26px 26px; }
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(35,107,104,.13); }

@media (max-width: 980px) {
  .sidebar { padding: 16px; }
  .theme-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-grid { min-height: 760px; }
}

@media (max-width: 650px) {
  .topbar { height: 72px; padding: 0 14px; }
  .brand-mark { width: 42px; height: 42px; }
  .brand h1 { font-size: 18px; }
  .layout { min-height: calc(100vh - 72px); }
  .calendar-area { padding: 14px 8px 24px; }
  .calendar-card, .calendar-toolbar { min-width: 720px; }
  .calendar-grid { grid-template-rows: repeat(6, 112px); min-height: 672px; }
  .theme-list { grid-template-columns: 1fr; }
}

/* Mobilni zaklenjeni prikaz: cel mesec brez vodoravnega drsnika */
@media (max-width: 650px) {
  .embed-mode .layout { display: block; }
  .embed-mode .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
    border-bottom: 1px solid var(--line);
  }
  .embed-mode .sidebar .panel {
    padding: 11px 12px;
    border-radius: 12px;
  }
  .embed-mode .panel-heading { margin-bottom: 8px; }
  .embed-mode .theme-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px 8px;
  }
  .embed-mode .theme-item {
    grid-template-columns: 16px 9px minmax(0, 1fr);
    gap: 5px;
    font-size: 10px;
  }
  .embed-mode .theme-dot { width: 8px; height: 8px; }
  .embed-mode .hint { display: none; }
  .embed-mode .calendar-area {
    width: 100%;
    padding: 8px 4px 18px;
    overflow-x: hidden;
  }
  .embed-mode .calendar-toolbar {
    min-width: 0;
    min-height: 48px;
    grid-template-columns: auto 1fr;
    gap: 8px;
    margin-bottom: 6px;
  }
  .embed-mode .calendar-toolbar h2 {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    font-size: clamp(20px, 7vw, 28px);
  }
  .embed-mode .toolbar-spacer { display: none; }
  .embed-mode .month-nav { grid-column: 1; grid-row: 1; gap: 4px; }
  .embed-mode .month-nav .icon-btn { width: 36px; height: 36px; }
  .embed-mode .month-nav .secondary-btn { padding: 8px 9px; }
  .embed-mode .calendar-card { min-width: 0; width: 100%; border-radius: 13px; }
  .embed-mode .weekday-row div { padding: 9px 1px; font-size: 9px; }
  .embed-mode .calendar-grid {
    grid-template-rows: repeat(6, minmax(78px, auto));
    min-height: 468px;
  }
  .embed-mode .day-cell { min-height: 78px; padding: 3px; }
  .embed-mode .day-number {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    font-size: 12px;
  }
  .embed-mode .day-header { margin-bottom: 2px; }
  .embed-mode .events { gap: 2px; }
  .embed-mode .event-chip {
    min-height: 19px;
    padding: 4px 3px;
    border-left-width: 2px;
    border-radius: 5px;
    font-size: 8px;
    line-height: 1.1;
  }
  .embed-mode .more-events { padding: 1px; font-size: 8px; }
}

@media (max-width: 390px) {
  .embed-mode .calendar-toolbar h2 { font-size: 19px; }
  .embed-mode .month-nav .secondary-btn { display: none; }
  .embed-mode .calendar-grid { grid-template-rows: repeat(6, minmax(72px, auto)); min-height: 432px; }
  .embed-mode .day-cell { min-height: 72px; }
}
