:root {
  --bg: #eef3f6;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --line: #d8e0e6;
  --line-strong: #bdc9d2;
  --text: #17202a;
  --muted: #667684;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e4f3f1;
  --blue: #245c9f;
  --blue-soft: #e6eef8;
  --amber: #946200;
  --amber-soft: #fff2cf;
  --danger: #b42318;
  --danger-soft: #fde8e4;
  --shadow: 0 18px 42px rgba(31, 45, 61, 0.09);
  --shadow-soft: 0 8px 22px rgba(31, 45, 61, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(230, 238, 248, 0.75) 0, rgba(243, 246, 248, 0) 260px),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  color: var(--text);
  font-weight: 750;
  letter-spacing: 0;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.main-nav a {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 600;
}

.main-nav a:hover,
.main-nav a.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-decoration: none;
}

.user-box {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-name {
  max-width: 220px;
  overflow: hidden;
  color: var(--text);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-link {
  color: var(--muted);
}

.page {
  width: min(1200px, calc(100vw - 32px));
  margin: 26px auto 56px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.panel {
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel:hover {
  box-shadow: 0 20px 46px rgba(31, 45, 61, 0.1);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.auth-panel {
  width: min(460px, 100%);
  margin: 80px auto;
  text-align: center;
}

.login-note {
  margin: 12px auto 0;
  max-width: 360px;
  color: var(--muted);
}

.telegram-login-button {
  width: min(100%, 320px);
  min-height: 48px;
  margin-top: 20px;
  border-color: #2481cc;
  background: #2481cc;
  font-size: 15px;
}

.telegram-login-button:hover {
  background: #1b6fab;
}

.login-status {
  margin: 12px auto 0;
  max-width: 340px;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.compact-stats .stat-card {
  min-height: 84px;
}

.today-board {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

.today-main {
  min-height: 240px;
}

.duty-card-list {
  display: grid;
  gap: 12px;
}

.duty-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbfb 100%);
  box-shadow: var(--shadow-soft);
}

.duty-card.is-done {
  border-color: #9bd0c4;
  background: linear-gradient(180deg, #ffffff 0%, #ecf7f5 100%);
}

.duty-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

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

.mini-list {
  display: grid;
  gap: 8px;
}

.mini-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.mini-list a:hover {
  border-color: #9cc8c2;
  background: var(--accent-soft);
  text-decoration: none;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 154px;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 16px;
}

.stat-card {
  min-height: 96px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 32px;
  line-height: 1;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tabs a {
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-weight: 650;
}

.tabs a:hover,
.tabs .active {
  border-color: #9cc8c2;
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-decoration: none;
}

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.flash-success {
  border-color: #90cbbf;
  background: var(--accent-soft);
}

.flash-error {
  border-color: #f2a7a0;
  background: var(--danger-soft);
  color: var(--danger);
}

.error-cell {
  max-width: 420px;
  white-space: normal;
  word-break: break-word;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

tbody tr:hover {
  background: var(--panel-soft);
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 13px;
}

.checkbox-label input {
  width: auto;
  min-height: auto;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--accent);
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: span 2;
}

button,
.button {
  min-height: 38px;
  border: 1px solid var(--accent-strong);
  border-radius: 7px;
  padding: 8px 13px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:hover,
.button:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

button.secondary {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--text);
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--panel-soft);
}

.button.secondary {
  display: inline-flex;
  align-items: center;
  border-color: var(--line-strong);
  background: #fff;
  color: var(--text);
}

.link-button {
  min-height: auto;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-strong);
}

.link-button:hover {
  background: transparent;
  text-decoration: underline;
}

.link-button.danger {
  color: var(--danger);
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.checks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 14px;
  margin: 12px 0;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.checks input {
  width: auto;
  min-height: auto;
}

.checkbox-line {
  align-items: center;
  color: var(--text);
  display: flex;
  font-size: 13px;
  font-weight: 700;
  gap: 8px;
  margin: 14px 0 8px;
}

.checkbox-line input {
  min-height: auto;
  width: auto;
}

.role-editor {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.list {
  display: grid;
  gap: 8px;
}

.list.compact {
  margin-top: 12px;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:hover {
  text-decoration: none;
}

.muted {
  color: var(--muted);
}

code {
  word-break: break-all;
}

.setup-note {
  margin-top: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.setup-note ol {
  margin: 8px 0 0;
  padding-left: 20px;
}

.setup-note li + li {
  margin-top: 5px;
}

.bot-stats .stat-card strong {
  font-size: 28px;
}

.bot-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.bot-status-grid > div,
.bot-actions form {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.bot-status-grid p,
.bot-actions p {
  margin: 7px 0 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.status-badge.success {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-badge.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.diagnostic-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.diagnostic-card strong {
  display: block;
  margin: 6px 0;
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagnostic-card p {
  margin: 0;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--line-strong);
}

.diagnostic-card.success .status-dot {
  background: var(--accent);
}

.diagnostic-card.warning .status-dot {
  background: var(--amber);
}

.diagnostic-card.danger .status-dot {
  background: var(--danger);
}

.digest-now-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.today-notify-panel {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

.today-notify-panel h2,
.today-notify-panel p {
  margin: 0;
}

.today-notify-panel p {
  margin-top: 6px;
}

.today-notify-panel button {
  white-space: nowrap;
}

.form-hint {
  margin: 10px 0 0;
}

.bot-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.bot-actions button {
  width: 100%;
}

.deploy-commands {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.deploy-commands code {
  display: block;
  padding: 11px 12px;
  border-radius: 7px;
  background: #13202b;
  color: #f6fafc;
  font-size: 13px;
}

.calendar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.calendar-actions strong {
  min-width: 190px;
  text-align: center;
  font-size: 15px;
}

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

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(100px, 1fr));
  min-width: 760px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  gap: 1px;
}

.calendar-weekday {
  min-height: 36px;
  padding: 9px 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.calendar-cell {
  min-height: 126px;
  padding: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 0.15s ease, outline-color 0.15s ease;
}

.calendar-cell-empty {
  background: #edf2f5;
}

.calendar-cell.today .calendar-day-head {
  background: var(--blue-soft);
  color: var(--blue);
}

.calendar-cell.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}

.calendar-day-head {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 800;
}

.shift-card {
  display: grid;
  gap: 2px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid #94c7bf;
  border-radius: 7px;
  background: linear-gradient(180deg, #ffffff 0%, #ecf7f5 100%);
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.12);
  cursor: grab;
}

.shift-card.is-done {
  border-color: #9bd0c4;
  background: linear-gradient(180deg, #ffffff 0%, #eef8f4 100%);
}

.shift-card:active {
  cursor: grabbing;
}

.shift-card.is-readonly,
.shift-card.is-readonly:active {
  cursor: default;
}

.shift-card strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
}

.shift-card span,
.shift-card small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shift-card.is-dragging {
  opacity: 0.55;
}

.calendar-hint {
  margin: 10px 0 0;
}

.calendar-context-menu {
  position: fixed;
  z-index: 100;
  display: grid;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(31, 45, 61, 0.18);
}

.calendar-context-menu[hidden],
.calendar-modal[hidden] {
  display: none;
}

.calendar-context-menu button {
  justify-content: flex-start;
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.calendar-context-menu button:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.calendar-context-menu button.danger {
  color: var(--danger);
}

.calendar-context-menu button.danger:hover {
  background: var(--danger-soft);
}

.calendar-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
}

.calendar-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 42, 0.38);
}

.calendar-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(460px, 100%);
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(23, 32, 42, 0.24);
}

@media (max-width: 860px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
  }

  .main-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .user-box {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

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

  .page {
    width: min(100% - 20px, 1200px);
    margin-top: 16px;
  }

  .auth-panel {
    margin: 18px auto 32px;
    padding: 16px;
  }

  .auth-panel h1 {
    font-size: 24px;
  }

  .grid.two,
  .stats-grid,
  .today-board,
  .bot-status-grid,
  .bot-actions,
  .diagnostic-grid,
  .form-grid,
  .checks {
    grid-template-columns: 1fr;
  }

  .calendar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .today-notify-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .today-notify-panel button {
    width: 100%;
  }

  .calendar-actions strong {
    min-width: 130px;
  }

  .wide {
    grid-column: auto;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
