﻿:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --day-other: #f6f8fb;
    --day-weekend: #fbfcfe;
    --border: #d9dee8;
    --border-strong: #c7cedb;
    --text: #172033;
    --muted: #697386;
    --muted-light: #99a3b3;
    --primary: #246bfe;
    --primary-dark: #1d56d4;
    --primary-soft: #e9f0ff;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --success: #15803d;
    --radius: 8px;
    --shadow: 0 12px 28px rgba(23, 32, 51, 0.12);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  }

  [data-theme="dark"] {
    --bg: #212529;
    --panel: #242624;
    --panel-soft: #2c2f2c;
    --day-other: #2a2c2a;
    --day-weekend: #303330;
    --border: #4a4d4a;
    --border-strong: #60645f;
    --text: #f1f3ef;
    --muted: #c0c7bd;
    --muted-light: #8f988d;
    --primary: #aac7ff;
    --primary-dark: #d0bcff;
    --primary-soft: #4a514a;
    --danger: #ffb5a0;
    --danger-soft: #5a3831;
    --success: #b1d18a;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; min-height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }
  button, input, textarea { font: inherit; }
  button { cursor: pointer; }
  .hidden { display: none !important; }

  .app {
    max-width: 1180px;
    min-height: 100vh;
    margin: 0 auto;
    padding: 0 18px 34px;
  }

  .navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    margin-bottom: 18px;
    padding: 10px 18px;
    background: #212529;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
    flex-wrap: wrap;
  }

  .navbar-left, .navbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }
  .navbar-right {
    flex: 1;
    justify-content: flex-end;
  }
  .navbar-brand {
    color: #ffffff;
    font-size: 20px;
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
  }
  .navbar .btn {
    background: #2b3035;
    border-color: #495057;
    color: rgba(255, 255, 255, .88);
  }
  .navbar .btn:hover {
    background: #343a40;
    border-color: #6c757d;
    color: #ffffff;
  }
  .navbar .btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #000000;
  }
  .navbar .btn.primary:hover {
    filter: brightness(.94);
    color: #000000;
  }
  .calendar-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin: 0 0 14px;
    flex-wrap: wrap;
  }

  .month-title {
    margin: 0;
    min-width: 230px;
    font-size: 22px;
    line-height: 1.2;
    font-weight: 750;
  }

  .btn {
    min-height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    padding: 7px 13px;
    font-weight: 650;
    transition: background .15s, border-color .15s, color .15s;
  }
  .btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
  .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
  .btn.primary:hover { background: var(--primary-dark); color: #fff; }
  .btn.danger { color: var(--danger); border-color: #f4b4b4; }
  .btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
  .full-width { width: 100%; }
  .icon-btn {
    width: 36px;
    padding: 0;
    font-size: 20px;
    line-height: 1;
  }
  .theme-toggle {
    width: 36px;
    min-width: 36px;
    padding: 0;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .view-switcher {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--panel-soft);
  }
  .view-btn {
    min-height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    padding: 5px 10px;
    font-weight: 750;
  }
  .view-btn.active {
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(23, 32, 51, 0.12);
  }

  .user-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, .72);
    font-size: 14px;
  }
  .user-name { color: #ffffff; font-weight: 700; }
  .sync-status {
    padding: 5px 8px;
    border: 1px solid #495057;
    border-radius: 999px;
    color: rgba(255, 255, 255, .78);
    font-size: 12px;
    font-weight: 750;
    white-space: nowrap;
  }
  .sync-status.offline {
    border-color: #ffb5a0;
    color: #ffb5a0;
  }
  .sync-status.pending {
    border-color: #dbc66e;
    color: #dbc66e;
  }

  .calendar {
    overflow: visible;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 1px 3px rgba(23, 32, 51, 0.06);
  }

  .weekdays, .grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .weekday {
    padding: 10px 6px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-soft);
    color: var(--muted);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-size: 12px;
    font-weight: 750;
  }
  .weekday.weekend { color: var(--danger); }
  .calendar.day-view .weekdays,
  .calendar.day-view .grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .calendar.week-view .weekdays {
    display: none;
  }
  .calendar.week-view .grid {
    display: flex;
    flex-direction: column;
  }
  .calendar.week-view .day {
    min-height: 96px;
    border-right: 0;
  }
  .calendar.week-view .day:nth-child(7n) {
    border-right: 0;
  }
  .week-day-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
    text-transform: uppercase;
  }

  .day {
    position: relative;
    min-height: 118px;
    padding: 8px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--panel);
  }
  .day.weekend::before {
    content: "";
    position: absolute;
    inset: 0;
    background: #ffc0cb;
    opacity: 0.2;
    pointer-events: none;
    z-index: 0;
  }
  .day > * {
    position: relative;
    z-index: 1;
  }
  .day:hover { z-index: 6; }
  .day:nth-child(7n) { border-right: 0; }
  .day.other { background: var(--day-other); color: var(--muted-light); }
  .day.weekend:not(.other) { background: var(--day-weekend); }
  .day:hover { background: var(--primary-soft); }

  .day-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
  }
  .day-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 750;
  }
  .today .day-number { background: var(--primary); color: #fff; }
  .small-add {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--panel);
    color: var(--primary);
    font-size: 20px;
    line-height: 1;
    font-weight: 700;
  }
  .small-add:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

  .day-count {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }

  .events {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
  }
  .event {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    padding: 3px 6px;
    border: 0;
    border-radius: 6px;
    color: #000000;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    overflow: hidden;
  }
  .event span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .event-color-0 { background: #dbc66e; }
  .event-color-1 { background: #aac7ff; }
  .event-color-2 { background: #b1d18a; }
  .event-color-3 { background: #ffb5a0; }
  .event-color-4 { background: #d0bcff; }
  .event.pending {
    outline: 2px dashed rgba(0, 0, 0, .45);
    outline-offset: -2px;
  }
  .more {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 2px 4px;
    text-align: left;
    font-size: 12px;
    font-weight: 750;
  }
  .overflow-panel {
    position: absolute;
    left: 6px;
    right: 6px;
    top: calc(100% - 8px);
    display: none;
    min-width: 210px;
    max-height: 280px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    z-index: 20;
  }
  .day:nth-child(7n) .overflow-panel {
    left: auto;
    right: 6px;
  }
  .day.has-overflow:hover .overflow-panel {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background: linear-gradient(135deg, #eef3ff, #f8fafc 48%, #edf7f1);
  }
  .auth-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
  }
  .auth-card h1 { margin: 0 0 8px; font-size: 25px; }
  .auth-card p { margin: 0 0 20px; color: var(--muted); }
  .auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    margin-bottom: 18px;
    background: var(--panel-soft);
    border-radius: var(--radius);
  }
  .auth-tab {
    border: 0;
    border-radius: 6px;
    padding: 8px;
    background: transparent;
    font-weight: 750;
    color: var(--muted);
  }
  .auth-tab.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(23, 32, 51, 0.1); }

  .field { margin-bottom: 13px; }
  .field label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
  }
  .field input, .field textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 8px 10px;
    background: var(--panel);
    color: var(--text);
  }
  .field textarea {
    min-height: 120px;
    resize: vertical;
  }
  #eventDescription {
    display: block;
    width: 100%;
    height: 120px;
    min-height: 120px;
    max-width: 100%;
    background: var(--panel);
    color: var(--text);
    border-color: var(--border-strong);
  }
  .field input:focus, .field textarea:focus {
    outline: 3px solid rgba(36, 107, 254, .18);
    border-color: var(--primary);
  }
  .form-error {
    min-height: 20px;
    color: var(--danger);
    font-size: 13px;
    font-weight: 650;
  }

  .modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(23, 32, 51, .42);
  }
  .modal {
    width: min(430px, 100%);
    max-height: 88vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .modal-head, .modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--border);
  }
  .modal-foot {
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    border-bottom: 0;
  }
  .day-add-btn { margin-top: 12px; }
  .modal-head h2 { margin: 0; font-size: 17px; }
  .modal-body { padding: 17px; overflow: auto; }
  .close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
  }
  .close:hover { background: var(--panel-soft); color: var(--text); }

  .swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid transparent;
  }
  .swatch.active { border-color: var(--text); }

  .day-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .day-row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius);
    background: var(--panel-soft);
  }
  .dot { width: 10px; height: 10px; border-radius: 50%; }
  .day-row-title { min-width: 0; overflow-wrap: anywhere; font-weight: 650; }
  .row-action {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 800;
  }
  .row-action:hover { background: var(--border); color: var(--text); }
  .row-action.delete:hover { background: var(--danger-soft); color: var(--danger); }
  .empty { color: var(--muted); font-size: 14px; }
  .status { margin: 18px 0; color: var(--muted); font-weight: 650; }

  @media (max-width: 700px) {
    .app { padding: 10px 7px 24px; }
    .navbar { margin-top: -10px; margin-bottom: 12px; padding: 10px 8px; }
    .navbar-right { justify-content: flex-start; flex: 0 1 auto; }
    .calendar-controls { justify-content: center; }
    .month-title { min-width: 170px; font-size: 18px; }
    .weekday { padding: 8px 2px; font-size: 10px; }
    .day { min-height: 82px; padding: 5px 4px; }
    .event { min-height: 21px; padding: 2px 4px; font-size: 10px; }
    .small-add { width: 24px; height: 24px; font-size: 18px; }
    .day-count { display: none; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal { width: 100%; border-radius: var(--radius) var(--radius) 0 0; }
  }
