:root {
  --bg: #f4f6fb;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --surface-soft: #f7f8fc;
  --text: #111426;
  --muted: #71778d;
  --border: #e4e7f0;
  --border-strong: #d5d9e6;
  --shadow: 0 18px 50px rgba(31, 38, 66, 0.1);
  --purple: #7357ff;
  --purple-soft: #eeeaff;
  --green: #24b78a;
  --green-soft: #e8fbf4;
  --amber: #e4a72b;
  --amber-soft: #fff6df;
  --pink: #e94f8c;
  --pink-soft: #ffeaf2;
  --danger: #d8485c;
  --danger-soft: #fff0f2;
  --radius: 24px;
  --radius-sm: 14px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0b0d14;
  --surface: rgba(18, 21, 31, 0.94);
  --surface-solid: #12151f;
  --surface-soft: #171b27;
  --text: #f4f6ff;
  --muted: #959db5;
  --border: #292e3e;
  --border-strong: #394053;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --purple-soft: #272044;
  --green-soft: #15372f;
  --amber-soft: #3c311c;
  --pink-soft: #3d1e2d;
  --danger-soft: #3b1e25;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% -8%, rgba(115, 87, 255, 0.12), transparent 30%),
    radial-gradient(circle at 92% 0%, rgba(36, 183, 138, 0.08), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background .2s ease, color .2s ease;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
a { color: inherit; }
[hidden] { display: none !important; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.app-shell { width: min(1840px, calc(100% - 24px)); margin: 12px auto 28px; }
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px 12px 18px;
  border-radius: 22px;
  position: sticky;
  top: 8px;
  z-index: 20;
}
.brand, .appbar-actions, .date-switcher, .column-tools, .log-dock-actions, .section-actions { display: flex; align-items: center; }
.brand { gap: 11px; min-width: 190px; }
.brand-mark { width: 13px; height: 13px; border-radius: 5px; background: linear-gradient(135deg, #927bff, #5d3cff); box-shadow: 0 0 0 5px var(--purple-soft); flex: 0 0 auto; }
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 15px; }
.brand-copy span { color: var(--muted); font-size: 12px; }
.appbar-actions { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.date-switcher { gap: 6px; padding: 4px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 14px; }
.date-switcher input { border: 0; background: transparent; color: var(--text); padding: 7px 4px; min-width: 138px; outline: none; }

button, .bot-button { border: 0; border-radius: 12px; transition: transform .14s ease, background .14s ease, border-color .14s ease, opacity .14s ease; }
button:hover:not(:disabled), .bot-button:hover { transform: translateY(-1px); }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; background: var(--surface-soft); color: var(--text); border: 1px solid var(--border); }
.ghost-button, .secondary-button, .danger-button, .primary-button, .telegram-button, .bot-button { min-height: 38px; padding: 9px 14px; font-weight: 700; text-decoration: none; text-align: center; }
.ghost-button { color: var(--text); background: transparent; border: 1px solid var(--border); }
.secondary-button { color: var(--text); background: var(--surface-soft); border: 1px solid var(--border); }
.primary-button { color: white; background: linear-gradient(135deg, #846cff, #6847f5); }
.danger-button { color: var(--danger); background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 22%, transparent); }
.telegram-button { color: #fff; background: linear-gradient(135deg, #309bea, #197ac7); }
.group-button { background: linear-gradient(135deg, #24b78a, #128e69); }
.admin-button { color: var(--purple); border-color: color-mix(in srgb, var(--purple) 28%, var(--border)); background: var(--purple-soft); }
.large-button { min-height: 48px; }

.theme-switch { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; user-select: none; padding: 0 2px; }
.theme-switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 42px; height: 24px; padding: 3px; border-radius: 999px; background: var(--border-strong); display: block; transition: background .2s; }
.switch-thumb { display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 7px rgba(0,0,0,.2); transition: transform .2s; }
.theme-switch input:checked + .switch-track { background: var(--purple); }
.theme-switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }

.board { display: grid; grid-template-columns: repeat(6, minmax(230px, 1fr)); gap: 14px; margin-top: 14px; align-items: start; overflow-x: auto; padding-bottom: 4px; }
.column {
  min-height: 510px;
  padding: 16px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 14px 38px rgba(31, 38, 66, .07);
  position: relative;
  overflow: hidden;
}
.column::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--accent); }
.column-todo { --accent: #247bd6; --soft: color-mix(in srgb, #247bd6 12%, transparent); }
.column-working { --accent: var(--purple); --soft: var(--purple-soft); }
.column-done { --accent: var(--green); --soft: var(--green-soft); }
.column-review { --accent: #607080; --soft: color-mix(in srgb, #607080 13%, transparent); }
.column-questions { --accent: var(--amber); --soft: var(--amber-soft); }
.column-help { --accent: var(--pink); --soft: var(--pink-soft); }
.column-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.column-kicker, .eyebrow { margin: 0 0 5px; color: var(--accent, var(--purple)); font-size: 11px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.column h2 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.column-tools { gap: 8px; }
.counter { min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 10px; border-radius: 11px; color: var(--accent); background: var(--soft); font-weight: 900; }
.column-add-toggle { width: 34px; height: 34px; border-radius: 11px; background: var(--accent); color: white; font-size: 22px; line-height: 1; }
.column-add-toggle[aria-expanded="true"] { transform: rotate(45deg); }

.column-add-form { display: grid; gap: 9px; padding: 12px; margin-bottom: 10px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 16px; }
.link-builder { display: grid; gap: 7px; }
.link-builder[hidden] { display: none; }
.link-rows { display: grid; gap: 7px; }
.link-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) 30px; gap: 6px; align-items: center; }
.link-row input { min-width: 0; min-height: 36px; padding: 7px 9px; font-size: 12px; }
.link-row .mini-button { width: 30px; min-height: 30px; padding: 0; font-size: 17px; }
textarea, input, select { color: var(--text); background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: 12px; outline: none; }
textarea:focus, input:focus, select:focus { border-color: var(--purple); box-shadow: 0 0 0 3px color-mix(in srgb, var(--purple) 14%, transparent); }
textarea { resize: vertical; min-height: 72px; padding: 11px 12px; }
input, select { min-height: 42px; padding: 9px 11px; }
.inline-form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.task-list { display: grid; gap: 9px; min-height: 70px; align-content: start; }
.task-card {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  grid-template-areas: "drag content" "drag actions";
  align-items: start;
  gap: 6px 10px;
  width: 100%;
  min-height: 0;
  height: auto;
  padding: 12px 12px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  background: var(--surface-solid);
  box-shadow: 0 8px 20px rgba(31,38,66,.04);
  cursor: grab;
}
.task-card:hover { border-color: color-mix(in srgb, var(--accent, var(--purple)) 48%, var(--border)); }
.task-card.dragging { opacity: .48; transform: rotate(1deg); }
.drag-handle { grid-area: drag; align-self: start; width: 22px; height: 28px; padding: 0; background: transparent; color: var(--muted); cursor: grab; font-size: 13px; letter-spacing: -2px; }
.task-content { grid-area: content; min-width: 0; display: grid; gap: 5px; }
.task-text { margin: 0; font-size: 14px; line-height: 1.42; white-space: pre-wrap; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 5px; min-height: 0; margin-top: -2px; }
.task-meta:empty { display: none; }
.task-meta span { max-width: 100%; color: var(--muted); font-size: 11px; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-meta span[data-type="project"] { color: var(--accent, var(--purple)); }
.task-links { display: grid; gap: 3px; min-width: 0; }
.task-links:empty { display: none; }
.task-link { width: fit-content; max-width: 100%; color: #247bd6; font-size: 12px; font-weight: 750; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-link:hover { text-decoration: underline; }
.task-time { width: fit-content; color: var(--muted); font-size: 11px; font-weight: 800; }
.task-time:empty { display: none; }
.task-actions { grid-area: actions; display: flex; gap: 10px; margin-top: 3px; min-height: 22px; align-items: center; }
.task-action { padding: 2px 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; border-radius: 0; }
.task-action:hover { color: var(--text); transform: none !important; }
.task-action.timer-action { color: var(--accent, var(--purple)); }
.task-action.danger:hover { color: var(--danger); }
.column.drag-over { outline: 2px dashed var(--accent); outline-offset: -7px; }

.log-dock { margin-top: 14px; border-radius: 20px; padding: 11px 13px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 16px; align-items: center; }
.log-dock-summary { display: flex; align-items: center; gap: 10px; min-width: 0; }
.log-dock-summary div { display: grid; gap: 1px; }
.log-dock-summary strong { font-size: 13px; }
.log-dock-summary small { color: var(--muted); font-size: 11px; }
.log-ready-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px var(--green-soft); }
.log-dock-actions { gap: 8px; }
.log-preview-wrap { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 10px; }
.log-preview { margin: 0; max-height: 260px; overflow: auto; white-space: pre-wrap; font: 13px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(460px, 100%); padding: 30px; border-radius: 28px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 11px; font-weight: 850; }
.login-copy { margin: 40px 0 22px; }
.login-copy h1 { margin: 0 0 12px; font-size: clamp(30px, 6vw, 44px); line-height: 1.02; letter-spacing: -.045em; }
.login-copy p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.login-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 12px; width: 100%; min-width: 0; }
.login-form > *, .login-card .bot-button { width: 100%; min-width: 0; max-width: 100%; }
.login-form label { font-size: 13px; font-weight: 800; }
.login-form input { min-height: 58px; text-align: center; font-size: 26px; font-weight: 900; letter-spacing: .22em; }
.bot-button { display: block; color: #fff; background: #229ed9; }
.login-note { margin-top: 15px; color: var(--muted); font-size: 12px; text-align: center; }
code { padding: 2px 5px; border-radius: 6px; background: var(--surface-soft); border: 1px solid var(--border); }

.modal { width: 100%; max-width: none; height: 100%; max-height: none; padding: 18px; border: 0; background: transparent; }
.modal::backdrop { background: rgba(6, 8, 14, .58); backdrop-filter: blur(5px); }
.modal-card { width: min(560px, 100%); max-height: calc(100vh - 36px); overflow: auto; margin: auto; padding: 22px; border-radius: 24px; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); }
.modal-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 20px; }
.modal-heading h2, .admin-section h3, .settings-section h3 { margin: 0; }
.dialog-close { width: 38px; height: 38px; border-radius: 12px; background: var(--surface-soft); color: var(--text); border: 1px solid var(--border); font-size: 22px; }
.field { display: grid; gap: 7px; margin-bottom: 13px; }
.field > span { font-size: 12px; font-weight: 800; }
.field small { color: var(--muted); font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.settings-card { width: min(620px, 100%); }
.settings-section { padding: 18px 0; border-top: 1px solid var(--border); }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section h3 { margin-bottom: 12px; font-size: 15px; }
.profile-card { display: flex; align-items: center; gap: 13px; padding: 13px; border-radius: 16px; background: var(--surface-soft); border: 1px solid var(--border); }
.profile-avatar { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, #846cff, #6847f5); font-weight: 900; }
.profile-card > div:last-child { display: grid; gap: 2px; }
.profile-card span, .profile-card small { color: var(--muted); font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.settings-hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 10px 0 0; }
.settings-footer { display: flex; justify-content: flex-end; }

.admin-modal { padding: 12px; }
.admin-card { width: min(1180px, 100%); padding: 0; }
.sticky-heading { position: sticky; top: 0; z-index: 3; padding: 20px 22px 14px; margin: 0; background: color-mix(in srgb, var(--surface-solid) 92%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); }
.admin-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 18px 22px 0; }
.stat-card { padding: 15px; border-radius: 16px; background: var(--surface-soft); border: 1px solid var(--border); }
.stat-card strong { display: block; font-size: 28px; }
.stat-card span { color: var(--muted); font-size: 12px; }
.admin-section { padding: 22px; border-top: 1px solid var(--border); }
.admin-section:first-of-type { border-top: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.section-heading h3 { font-size: 18px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.users-list { display: grid; gap: 8px; }
.user-row { display: grid; grid-template-columns: minmax(180px, 1.4fr) 140px 150px minmax(220px, auto); gap: 10px; align-items: center; padding: 11px 12px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface-soft); }
.user-main { min-width: 0; }
.user-main strong { display: block; overflow: hidden; text-overflow: ellipsis; }
.user-main small { color: var(--muted); }
.status-badge { width: fit-content; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.status-active { color: #128563; background: var(--green-soft); }
.status-pending { color: #a06e00; background: var(--amber-soft); }
.status-blocked, .status-rejected { color: var(--danger); background: var(--danger-soft); }
.user-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.mini-button { min-height: 30px; padding: 6px 9px; border: 1px solid var(--border); background: var(--surface-solid); color: var(--text); font-size: 11px; font-weight: 750; }
.mini-button.positive { color: #128563; }
.mini-button.negative { color: var(--danger); }
.role-select { min-height: 34px; padding: 5px 8px; font-size: 12px; }
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 9px; }
.feature-item, .check-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-soft); }
.check-row.compact { padding: 8px 9px; }
.feature-item input, .check-row input { width: 18px; height: 18px; accent-color: var(--purple); }
.feature-item span, .check-row span { font-size: 13px; font-weight: 700; }
.project-list { display: grid; gap: 8px; }
.project-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 9px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-soft); }
.project-row input { min-width: 0; }
.project-row .mini-button { white-space: nowrap; }
.section-actions { justify-content: flex-end; gap: 8px; margin-top: 13px; flex-wrap: wrap; }
.admin-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.full-row { grid-column: 1 / -1; }
.token-form { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--border-strong); }
.audit-list { display: grid; gap: 7px; max-height: 360px; overflow: auto; }
.audit-item { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 9px 10px; border-radius: 12px; background: var(--surface-soft); font-size: 12px; }
.audit-item time { color: var(--muted); }
.audit-empty, .users-empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 14px; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 2147483647; max-width: min(390px, calc(100% - 36px)); padding: 12px 15px; border-radius: 13px; color: white; background: #202538; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; }
.toast[data-type="error"] { background: #b7384c; }
.toast[data-type="success"] { background: #168a68; }

@media (max-width: 1280px) {
  .board { grid-template-columns: repeat(2, minmax(280px, 1fr)); }
  .column { min-height: 430px; }
  .feature-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .appbar { position: static; align-items: flex-start; flex-direction: column; }
  .appbar-actions { width: 100%; justify-content: flex-start; }
  .date-switcher { flex: 1 1 auto; }
  .user-row { grid-template-columns: 1fr 120px; }
  .user-row .role-cell { grid-column: 1; }
  .user-actions { grid-column: 2; grid-row: 1 / span 2; }
}
@media (max-width: 680px) {
  .app-shell { width: min(100% - 12px, 1840px); margin-top: 6px; }
  .board { grid-template-columns: 1fr; gap: 10px; }
  .column { min-height: 330px; border-radius: 20px; }
  .appbar { border-radius: 18px; }
  .appbar-actions { gap: 6px; }
  .date-switcher { width: 100%; }
  .date-switcher input { min-width: 0; flex: 1; }
  .today-button { display: none; }
  .telegram-button { flex: 1 1 150px; }
  .log-dock { grid-template-columns: 1fr; }
  .log-dock-actions { justify-content: flex-end; }
  .settings-grid, .feature-grid, .admin-form-grid, .admin-stats { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr; }
  .user-actions, .user-row .role-cell { grid-column: 1; grid-row: auto; justify-content: flex-start; }
  .audit-item { grid-template-columns: 1fr; gap: 3px; }
  .modal { padding: 7px; }
  .modal-card { max-height: calc(100vh - 14px); border-radius: 19px; }
}
