:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dbe2ea;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --success: #166534;
  --success-bg: #dcfce7;
  --warning: #92400e;
  --warning-bg: #fef3c7;
  --chief: #1d4ed8;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.container {
  width: min(1900px, 100%);
  margin: 0 auto;
  padding: 16px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
h1 { margin: 0 0 4px 0; font-size: 28px; }
h2 { margin-top: 0; font-size: 22px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-note { font-size: 12px; margin-top: 4px; }
.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.auth-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
.toolbar-grid { grid-template-columns: minmax(220px,1fr) minmax(220px,1fr) auto; align-items: end; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
input, select, button, textarea { font: inherit; }
input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
  background: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
}
button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}
button:hover:not(:disabled) { background: var(--primary-dark); }
button.secondary { background: #eef2ff; color: #1e3a8a; }
button.secondary:hover:not(:disabled) { background: #e0e7ff; }
button.ghost-danger { background: #fee2e2; color: #b91c1c; }
button.ghost-danger:hover:not(:disabled) { background: #fecaca; }
.success-btn { background: #16a34a; }
.success-btn:hover:not(:disabled) { background: #15803d; }
.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-top: 32px;
}
.message {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  display: none;
}
.message.error { display: block; background: var(--danger-bg); color: var(--danger); }
.message.success { display: block; background: var(--success-bg); color: var(--success); }
.message.warning { display: block; background: var(--warning-bg); color: var(--warning); }
.error { background: var(--danger-bg); border-color: #fecaca; color: var(--danger); }
.warning-card { background: var(--warning-bg); border-color: #fcd34d; }
.preview {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fafafa;
}
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tab-btn { background: #e2e8f0; color: #0f172a; }
.tab-btn.active { background: var(--primary); color: #fff; }
.planner-controls-card { margin-bottom: 12px; }
.sticky-works-card {
  position: static;
}
.compact-header { margin-bottom: 6px; }
.compact-note { margin: 0 0 8px 0; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.schedule-toolbar {
  display: grid;
  grid-template-columns: minmax(280px,1fr) auto auto;
  gap: 16px;
  align-items: end;
}
.schedule-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.state-badge {
  min-width: 140px;
  justify-self: end;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--border);
}
.state-badge.editing { background: #dcfce7; color: #166534; border-color: #86efac; }
.state-badge.locked { background: #e2e8f0; color: #334155; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; }
.small-stats strong { font-size: 20px; }
.stats div { min-width: 80px; }
.stats strong { display: block; font-size: 22px; }
.stats span { color: var(--muted); font-size: 12px; }
.unit-tree {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fbfdff;
  overflow: auto;
  margin-top: 12px;
}
.unit-tree ul { list-style: none; margin: 0; padding-left: 22px; }
.unit-tree > ul { padding-left: 0; }
.unit-tree li { margin: 8px 0; position: relative; }
.unit-tree li::before { content: ''; position: absolute; left: -12px; top: 14px; width: 8px; border-top: 1px solid #cbd5e1; }
.unit-tree > ul > li::before { display: none; }
.tree-node {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 10px;
}
.tree-code { font-weight: 700; color: #1e3a8a; white-space: nowrap; }
.tree-name { font-weight: 600; }
.tree-meta { color: var(--muted); font-size: 12px; }
.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.works-wrap { max-height: none; overflow: visible; }
.staff-table,
.planned-table,
.users-table,
.attached-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: white;
}
.staff-table th,
.staff-table td,
.planned-table th,
.planned-table td,
.users-table th,
.users-table td,
.attached-table th,
.attached-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.staff-table th,
.planned-table th,
.users-table th,
.attached-table th { text-align: left; background: #f8fafc; position: sticky; top: 0; z-index: 2; }
.staff-main-row td { min-height: 64px; }
.staff-main-row.readonly-unit td { background: #f3f4f6; color: #6b7280; }
.staff-main-row.limited-fit td { background: #e0f2fe; }
.staff-main-row.limited-fit.readonly-unit td { background: #dbeafe; color: #64748b; }
.attach-main-row.limited-fit td { background: #e0f2fe; }
.staff-main-row.vacant td { background: #fafafa; }
.staff-main-row.invalid td { background: #fff7ed; }
.staff-main-row.is-chief td.col-name,
.staff-main-row.is-chief td.col-position { color: var(--chief); font-weight: 700; }
.details-box { padding: 10px 0; }
.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.detail-check { display:flex; align-items:center; gap:8px; font-weight:600; }
.detail-check input { width:18px; height:18px; }
.detail-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #fcfdff;
  min-width: 0;
}
.detail-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.detail-value { font-weight: 600; word-break: break-word; overflow-wrap: anywhere; }
.expand-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  padding: 0;
}
.table-control,
.table-text,
.table-number {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.table-text,
.readonly-box,
.staff-table td {
  word-break: break-word;
  overflow-wrap: anywhere;
}
.table-text { min-height: 44px; }
.invalid { border-color: #f59e0b !important; background: #fff7ed !important; }
.readonly-box {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: #f8fafc;
}
.readonly-box.empty { color: #94a3b8; }
.readonly-box.center { text-align: center; font-weight: 700; }
.planned-work-row.shortage td { background: #fee2e2; }
.col-expand { width: 42px; }
.col-check { width: 42px; text-align: center; }
.col-line-no { width: 54px; }
.col-name { width: 150px; }
.col-rank { width: 110px; }
.col-position { width: 170px; }
.col-status { width: 110px; }
.col-locality { width: 120px; }
.col-activity { width: 150px; }
.col-activity-readonly { width: 140px; }
.col-transferred { width: 130px; }
.col-note { width: 150px; }
.work-col-note { width: 220px; }
.work-col-jbd { width: 240px; }
.work-col-required,
.work-col-engaged,
.work-col-shortage { width: 110px; }
.work-col-actions { width: 110px; }
.users-table td:last-child,
.users-table th:last-child { width: 120px; }
.user-role,
.user-unit { min-width: 0; }
.save-row-btn { padding: 8px 10px; }
.waiting-note { padding: 16px; text-align: center; color: var(--muted); }
.flatpickr-day.has-saved-day::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #16a34a;
}
@media (max-width: 1200px) {
  .auth-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .toolbar-grid,
  .schedule-toolbar,
  .details-grid,
  .grid.two { grid-template-columns: 1fr; }
  .state-badge { justify-self: start; }
}

.assign-check { width: 18px; height: 18px; }
.note-cell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.note-pick {
  min-height: 36px;
  padding-top: 6px;
  padding-bottom: 6px;
}
.message > div + div {
  margin-top: 6px;
}

.attached-table td:last-child, .attached-table th:last-child { width: 110px; }
.col-attach-name{width:220px;}
.col-attach-rank{width:130px;}
.col-attach-position{width:220px;}
.col-attach-actions{width:110px;}
.attach-main-row td{min-height:56px;}
.attach-details .details-grid{grid-template-columns:repeat(2,minmax(0,1fr));}
.table-text.wrap{min-height:44px; white-space:normal;}

.attached-table .table-text, .attached-table .table-number { min-height: 38px; padding: 6px 8px; }
.attached-table .details-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }

.report-grid { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.report-block { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #fff; }
.report-block h3 { margin: 0; font-size: 20px; }
.report-block-disabled { opacity: 0.8; }
@media (max-width: 1100px) { .report-grid { grid-template-columns: 1fr; } }


.details-row.limited-fit td .details-box,
.details-row.attach-details.limited-fit td .details-box { background: #e0f2fe; }
