:root {
  --bg: #f8f9fa;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --border: #e5e7eb;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
}

/* Блокировка скролла на body */
body {
  overflow: hidden;
  height: 100vh;
  margin: 0;
  padding: 0;
}

body.loading {
  overflow: hidden;
}

body.logged-in {
  overflow: hidden;
}

/* Лоадер */
#initialLoader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#initialLoader.active {
  display: flex;
}

/* Views */
.view {
  display: none;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.view.active {
  display: flex;
}

/* Для loginView — центрирование */
#loginView {
  align-items: center;
  justify-content: center;
}

/* Для appView — вертикальный скролл только внутри main */
#appView {
  flex-direction: column;
}

#appView main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}


.view {
  display: none;
  opacity: 0;
  transition: opacity 0.15s ease-in;
}

.view.active {
  display: flex;
  opacity: 1;
}

/* Лоадер при инициализации */
#initialLoader {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#initialLoader.active {
  display: flex;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

.hidden { display: none !important; }

/* Login */
#loginView { align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
h1 { font-size: 22px; margin-bottom: 6px; text-align: center; }
.subtitle { color: var(--text-secondary); text-align: center; margin-bottom: 24px; font-size: 14px; }
.field { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: #444; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; outline: none; transition: border 0.2s; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
button { padding: 12px 16px; border: none; border-radius: 8px; font-size: 15px; font-weight: 500; cursor: pointer; transition: background 0.2s; }
.btn.primary { background: var(--primary); color: white; width: 100%; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f3f4f6; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Header */
header { background: var(--card); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
header h1 { font-size: 18px; margin: 0; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }

/* Calendar */
main { padding: 16px; flex: 1; }
.calendar-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; max-width: 1100px; margin: 0 auto; }
.month-block { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.month-title { font-size: 16px; font-weight: 600; margin-bottom: 10px; text-align: center; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-cell { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 8px; font-size: 14px; cursor: pointer; position: relative; transition: transform 0.1s; user-select: none; }
.day-cell:hover { transform: scale(1.05); }
.day-cell.empty { cursor: default; }
.day-cell .count { font-size: 11px; font-weight: 600; margin-top: 2px; }
.day-cell .indicator { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; }
.day-cell .check { position: absolute; top: 3px; right: 3px; font-size: 10px; }

/* Colors */
.bg-remove { background: #fee2e2; color: #991b1b; }
.bg-add { background: #d1fae5; color: #065f46; }
.bg-mixed { background: #fef3c7; color: #92400e; }
.ind-new { background: var(--danger); }
.ind-progress { background: var(--warning); }
.ind-done { color: var(--success); }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-content { background: var(--card); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); }
.modal-content.wide { max-width: 700px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.modal-actions button { width: auto; }

/* Table */
.req-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 12px; }
.req-table th, .req-table td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.req-table th { font-weight: 600; color: var(--text-secondary); font-size: 12px; }
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; }
.status-new { background: #fee2e2; color: #991b1b; }
.status-progress { background: #fef3c7; color: #92400e; }
.status-done { background: #d1fae5; color: #065f46; }

/* FAB */
.fab { position: fixed; bottom: 24px; right: 24px; background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 10px 16px; border-radius: 24px; font-size: 14px; z-index: 50; }

/* Массовый выбор дней */
body.select-mode .day-cell:not(.empty) { cursor: copy; }
.day-cell.selected { outline: 2px solid var(--primary); outline-offset: -2px; background: #dbeafe; color: #1e3a8a; }
.select-bar { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,0.12); border-radius: 24px; padding: 10px 18px; display: flex; align-items: center; gap: 14px; z-index: 60; font-size: 14px; }
.select-bar .btn { width: auto; }

/* Toast */
#toastContainer { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: white; padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); animation: fadein 0.3s; }
.toast.error { background: var(--danger); }
.toast.error.hidden { display: none; }
@keyframes fadein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile */
@media (max-width: 768px) {
  .calendar-grid { grid-template-columns: 1fr; }
  .modal-content { max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; align-self: flex-end; }
  .req-table { font-size: 13px; }
  .req-table th:nth-child(3), .req-table td:nth-child(3) { display: none; } /* hide comment on small screens */
}