:root {
      --bg: #f5f7fb;
      --card: #ffffff;
      --text: #172033;
      --muted: #64748b;
      --accent: #2563eb;
      --accent-soft: #eff6ff;
      --border: #e2e8f0;
      --danger: #b91c1c;
      --success: #166534;
      --success-soft: #f0fdf4;
      --shadow: 0 16px 36px rgba(15, 23, 42, 0.10);
    }

    * { box-sizing: border-box; }

    html, body { height: 100%; }

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

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

    button { cursor: pointer; }

    .hidden { display: none !important; }

    /* Firebase sign-in */
    .signin-screen {
      position: fixed;
      inset: 0;
      z-index: 9000;
      display: grid;
      place-items: center;
      padding: 24px;
      background: var(--bg);
    }

    .signin-card {
      width: min(470px, 100%);
      padding: 28px;
      border: 1px solid var(--border);
      border-radius: 22px;
      background: var(--card);
      text-align: center;
    }


    .signin-icon {
      display: grid;
      place-items: center;
      width: 54px;
      height: 54px;
      margin: 0 auto 16px;
      border-radius: 16px;
      background: var(--accent-soft);
      font-size: 1.7rem;
    }

    .signin-card h2 { margin: 0 0 8px; }

    .signin-card p {
      margin: 0 0 20px;
      color: var(--muted);
      line-height: 1.5;
    }

    .signin-error {
      min-height: 22px;
      margin-top: 12px;
      color: var(--danger);
      font-size: .9rem;
    }

    .config-warning {
      width: min(780px, calc(100% - 24px));
      margin: 20px auto;
      padding: 16px;
      border: 1px solid #f59e0b;
      border-radius: 14px;
      background: #fffbeb;
      color: #7c2d12;
      line-height: 1.5;
    }

    /* Main shell */
    .app-shell {
      height: 100vh;
      display: grid;
      grid-template-rows: auto minmax(0, 1fr);
      gap: 12px;
      padding: 16px;
      overflow: hidden;
    }

    .topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 14px;
      min-height: 58px;
    }

    .title-wrap {
      min-width: 0;
    }

    h1 {
      margin: 0 0 3px;
      font-size: clamp(1.65rem, 3vw, 2.35rem);
      letter-spacing: -0.035em;
      line-height: 1.05;
    }

    .subtitle {
      margin: 0;
      color: var(--muted);
      font-size: .9rem;
    }

    .top-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      justify-content: flex-end;
    }

    .button,
    .button-secondary,
    .button-danger {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      border-radius: 10px;
      padding: 9px 12px;
      text-decoration: none;
      font-weight: 700;
      border: 1px solid transparent;
      white-space: nowrap;
    }

    .button {
      background: var(--accent);
      color: white;
    }

    .button-secondary {
      background: var(--card);
      color: var(--text);
      border-color: var(--border);
    }

    .button-danger {
      background: #fff;
      color: var(--danger);
      border-color: #fecaca;
    }

    .user-chip {
      max-width: 210px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 8px 10px;
      border-radius: 999px;
      background: var(--accent-soft);
      color: var(--accent);
      font-size: .8rem;
      font-weight: 700;
    }

    .planner-layout {
      min-height: 0;
      display: grid;
      grid-template-columns: minmax(0, 1fr) 330px;
      gap: 12px;
    }

    /* Calendar */
    .calendar-panel,
    .task-panel {
      min-height: 0;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 18px;
    }

    .calendar-panel {
      display: grid;
      grid-template-rows: auto auto minmax(0, 1fr);
      gap: 7px;
      padding: 12px;
      overflow: hidden;
    }

    .calendar-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
    }

    .calendar-toolbar h2 {
      margin: 0;
      font-size: 1.18rem;
    }

    .month-controls {
      display: flex;
      gap: 6px;
      align-items: center;
    }

    .icon-button,
    .today-button {
      height: 34px;
      border: 1px solid var(--border);
      border-radius: 9px;
      background: var(--card);
      color: var(--text);
      font-weight: 700;
    }

    .icon-button {
      width: 34px;
      display: grid;
      place-items: center;
    }

    .today-button { padding: 0 10px; }

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

    .weekday {
      padding: 4px 3px;
      color: var(--muted);
      font-size: .72rem;
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: .04em;
      text-align: center;
    }

    .calendar-grid {
      min-height: 0;
      grid-template-rows: repeat(var(--weeks, 5), minmax(0, 1fr));
    }

    .day {
      position: relative;
      min-width: 0;
      min-height: 0;
      padding: 5px;
      overflow: hidden;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: #fff;
      transition: border-color .15s ease, background .15s ease;
    }

    .day.blank {
      background: #f8fafc;
      border-style: dashed;
    }

    .day.today {
      border-color: var(--accent);
      box-shadow: inset 0 0 0 1px var(--accent);
    }

    .day.drag-over,
    .day.click-target:hover {
      border-color: var(--accent);
      background: var(--accent-soft);
    }

    .date-number {
      display: inline-grid;
      place-items: center;
      width: 23px;
      height: 23px;
      border-radius: 7px;
      font-weight: 800;
      font-size: .76rem;
    }

    .day.today .date-number {
      color: white;
      background: var(--accent);
    }

    .day-items {
      display: grid;
      gap: 3px;
      margin-top: 3px;
      overflow: auto;
      max-height: calc(100% - 26px);
      scrollbar-width: thin;
    }

    .scheduled-task {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 4px;
      align-items: start;
      padding: 4px 5px;
      border: 1px solid #bfdbfe;
      border-radius: 7px;
      background: var(--accent-soft);
      color: var(--text);
      font-size: .68rem;
      cursor: pointer;
    }

    .scheduled-task.completed {
      border-color: #bbf7d0;
      background: var(--success-soft);
      color: #365314;
    }

    .scheduled-task.completed .scheduled-title {
      text-decoration: line-through;
      opacity: .75;
    }

    .scheduled-title {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-weight: 800;
    }

    .scheduled-meta {
      margin-top: 1px;
      color: var(--muted);
      font-size: .62rem;
      white-space: nowrap;
    }

    .status-dot {
      font-size: .7rem;
      line-height: 1;
      padding-top: 1px;
    }

    /* Sidebar */
    .task-panel {
      display: grid;
      grid-template-rows: auto auto auto minmax(0, 1fr);
      gap: 10px;
      padding: 12px;
      overflow: hidden;
    }

    .task-panel h2 {
      margin: 0 0 2px;
      font-size: 1.14rem;
    }

    .panel-subtitle {
      margin: 0;
      color: var(--muted);
      font-size: .78rem;
      line-height: 1.35;
    }

    .form-grid {
      display: grid;
      gap: 8px;
    }

    .field { min-width: 0; }

    .field label {
      display: block;
      margin-bottom: 3px;
      font-size: .72rem;
      font-weight: 800;
    }


    .field input,
    .field textarea,
    .field select {
      width: 100%;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: var(--card);
      color: var(--text);
    }

    .field input,
    .field textarea,
    .field select {
      padding: 7px 8px;
      font-size: .82rem;
    }

    .field textarea {
      min-height: 48px;
      max-height: 70px;
      resize: vertical;
    }

    .two-col {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 7px;
    }

    .duration-row {
      display: grid;
      grid-template-columns: 1fr 94px;
      gap: 5px;
    }

    .create-button {
      width: 100%;
      padding: 9px 12px;
      border: 0;
      border-radius: 10px;
      background: var(--accent);
      color: white;
      font-weight: 800;
    }

    .task-list-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .task-list-header h3 {
      margin: 0;
      font-size: .92rem;
    }

    .count-badge {
      display: inline-grid;
      place-items: center;
      min-width: 24px;
      height: 24px;
      padding: 0 7px;
      border-radius: 999px;
      background: var(--accent-soft);
      color: var(--accent);
      font-size: .72rem;
      font-weight: 800;
    }

    .task-list {
      min-height: 0;
      display: grid;
      align-content: start;
      gap: 6px;
      overflow-y: auto;
      padding-right: 2px;
    }

    .task-card {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 7px;
      padding: 8px;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: #fff;
      cursor: grab;
    }

    .task-card.selected {
      border-color: var(--accent);
      background: var(--accent-soft);
    }

    .task-name {
      margin: 0;
      font-size: .8rem;
      font-weight: 800;
      line-height: 1.3;
    }

    .task-meta,
    .task-note {
      margin-top: 2px;
      color: var(--muted);
      font-size: .69rem;
      line-height: 1.3;
    }

    .task-delete {
      border: 0;
      background: transparent;
      color: #94a3b8;
      padding: 0 1px;
    }

    .task-delete:hover { color: var(--danger); }

    .empty-tasks {
      padding: 12px;
      border: 1px dashed var(--border);
      border-radius: 10px;
      color: var(--muted);
      text-align: center;
      font-size: .76rem;
    }

    .selection-hint {
      min-height: 17px;
      margin: 0;
      color: var(--accent);
      font-size: .72rem;
      font-weight: 700;
    }

    /* Modal */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      z-index: 10000;
      display: grid;
      place-items: center;
      padding: 18px;
      background: rgba(15, 23, 42, .48);
    }

    .modal {
      width: min(560px, 100%);
      max-height: calc(100vh - 36px);
      overflow-y: auto;
      padding: 20px;
      border: 1px solid var(--border);
      border-radius: 18px;
      background: var(--card);
      box-shadow: var(--shadow);
    }

    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      gap: 12px;
      margin-bottom: 16px;
    }

    .modal-header h2 {
      margin: 0;
      font-size: 1.25rem;
    }

    .modal-close {
      width: 34px;
      height: 34px;
      display: grid;
      place-items: center;
      border: 1px solid var(--border);
      border-radius: 9px;
      background: #fff;
      color: var(--text);
    }

    .modal-actions {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-top: 16px;
    }

    .modal-actions button {
      flex: 1 1 130px;
    }

    .completed-banner {
      margin-bottom: 12px;
      padding: 10px 12px;
      border-radius: 10px;
      background: var(--success-soft);
      color: var(--success);
      font-size: .82rem;
      font-weight: 800;
    }

    .sync-status {
      margin: 0;
      font-size: .7rem;
      color: var(--muted);
    }

    @media (max-width: 900px) {
      body { overflow: auto; }

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

      .planner-layout {
        grid-template-columns: 1fr;
      }

      .calendar-panel {
        min-height: 680px;
      }

      .task-panel {
        min-height: 560px;
      }
    }

    @media (max-width: 620px) {
      .app-shell { padding: 10px; }

      .topbar {
        align-items: flex-start;
        flex-direction: column;
      }

      .top-actions {
        width: 100%;
        justify-content: flex-start;
      }

      .calendar-panel {
        overflow-x: auto;
      }

      .calendar-toolbar {
        min-width: 680px;
      }

      .weekdays,
      .calendar-grid {
        min-width: 680px;
      }

      .two-col {
        grid-template-columns: 1fr;
      }
    }
