:root {
  --bg: #f1f5f9;
  --paper: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #cbd5e1;
  --line-soft: #e2e8f0;
  --accent: #0d6e5b;
  --accent-hover: #095445;
  --accent-light: #e6f6f2;
  --accent-border: #86d4c2;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --sidebar: 268px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: var(--ink);
  font-size: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

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

button, a, input, textarea, select {
  outline-offset: 2px;
}

/* ================= BUTTONS ================= */
button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 500;
  padding: 9px 15px;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

button:hover:not(:disabled) {
  background: #f0fdf9;
  border-color: var(--accent);
  color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(13, 110, 91, 0.1);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

button.primary, .new-btn {
  background: linear-gradient(135deg, #0f766e 0%, #0b5d56 100%);
  color: #ffffff;
  border-color: #0b5d56;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(13, 110, 91, 0.25);
}

button.primary:hover:not(:disabled), .new-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #0d655e 0%, #084742 100%);
  border-color: #084742;
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(13, 110, 91, 0.35);
}

button.small {
  padding: 7px 12px;
  font-size: 12.5px;
  border-radius: 7px;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  padding: 6px 0;
  text-align: left;
  box-shadow: none;
}

.text-btn:hover:not(:disabled) {
  background: transparent;
  text-decoration: underline;
  transform: none;
  box-shadow: none;
}

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  padding: 5px 10px;
  box-shadow: none;
  color: var(--muted);
}

.icon-btn:hover:not(:disabled) {
  background: var(--line-soft);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

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

.danger:hover:not(:disabled) {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: #b91c1c;
}

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

/* ================= SIDEBAR ================= */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  z-index: 5;
  box-shadow: 2px 0 16px rgba(15, 23, 42, 0.03);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.brand b {
  font-weight: 400;
  color: var(--accent);
}

.brand small {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
  margin-top: 5px;
}

.brand-icon {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f766e, #0b554f);
  color: white;
  border-radius: 12px;
  width: 44px;
  height: 46px;
  font-weight: 800;
  font-size: 17px;
  box-shadow: 0 6px 14px rgba(13, 110, 91, 0.28);
}

.template-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 22px 0 14px;
  padding: 9px 12px;
  background: #f8fafc;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  height: 8px;
  width: 8px;
  display: inline-block;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.tag {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 10.5px;
  margin-left: auto;
}

.new-btn {
  width: 100%;
  text-align: left;
  font-weight: 600;
  padding: 12px 15px;
  font-size: 14px;
}

nav {
  overflow: auto;
  flex: 1;
  margin-top: 14px;
  padding-right: 2px;
}

nav button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  margin: 4px 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  padding: 11px 14px;
  border-radius: 9px;
  box-shadow: none;
}

nav button:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: transparent;
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

nav button[data-action="home"]:not(.active) {
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
  margin-bottom: 10px;
}

nav button[data-action="home"]:not(.active):hover {
  background: var(--accent-light);
  border-color: var(--accent-border);
  color: var(--accent);
}

nav button.active {
  background: var(--accent-light);
  border-color: var(--accent-border);
  color: var(--accent-hover);
  font-weight: 700;
  box-shadow: inset 4px 0 0 var(--accent);
}

nav .nav-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin: 20px 10px 8px;
  text-transform: uppercase;
}

.nav-guide {
  margin: 20px 4px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #f8fafc 0%, #f0fdf9 100%);
  border: 1px solid #ccebdfff;
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.7;
}

.nav-guide b {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  margin-bottom: 6px;
}

.nav-guide p {
  margin: 4px 0;
  font-weight: 500;
}

nav button.utility-link {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  text-align: center;
}

.sidebar-bottom {
  font-size: 12px;
  color: var(--ink-soft);
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  margin-top: 14px;
}

.sidebar-bottom p {
  font-size: 11.5px;
  color: var(--muted);
  margin: 6px 0;
}

/* ================= HEADER & SHELL ================= */
.shell {
  margin-left: var(--sidebar);
}

header {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 36px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 4;
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.eyebrow {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 1.4px;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-light);
  padding: 3px 8px;
  border-radius: 5px;
}

.header-title {
  font-size: 21px;
  font-weight: 700;
  margin-top: 5px;
  max-width: 560px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

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

.header-actions button {
  padding: 10px 18px;
  font-size: 13.5px;
}

.save-state {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.save-state.error {
  color: var(--danger);
  background: var(--danger-bg);
}

main {
  max-width: 1440px;
  margin: auto;
  padding: 28px 36px 90px;
}

/* ================= HOME / LIBRARY VIEW ================= */
.welcome {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 30px;
  margin: 0 0 24px;
  padding: 24px 28px;
  background: linear-gradient(135deg, #ffffff 0%, #f0fdf9 100%);
  border: 1px solid var(--accent-border);
  border-left: 5px solid var(--accent);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}

.welcome h1 {
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.6px;
  margin: 0 0 8px;
  color: var(--ink);
}

.welcome p {
  color: var(--ink-soft);
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.compact-welcome {
  margin: 0 0 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 20px 0 14px;
  flex-wrap: wrap;
}

.toolbar h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search {
  border: 1.5px solid var(--line);
  background: #ffffff;
  border-radius: 9px;
  padding: 10px 14px;
  min-width: 270px;
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 91, 0.15);
}

.card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}

.card-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-head h2, .card-head h3 {
  font-size: 16px;
  margin: 0;
  font-weight: 700;
  color: var(--ink);
}

.card-body {
  padding: 22px;
}

.hint, .muted {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.65;
}

.projects {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.projects th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  background: #f8fafc;
  color: var(--ink-soft);
  padding: 14px 20px;
  font-weight: 700;
  border-bottom: 1.5px solid var(--line);
}

.projects td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.projects tbody tr {
  transition: background 0.12s;
}

.projects tbody tr:hover {
  background: #f8fafc;
}

.projects tr:last-child td {
  border: 0;
}

.projects .select-col {
  width: 42px;
  padding-right: 0;
}

.projects input[type="checkbox"] {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  cursor: pointer;
}

.projects tr:has(input:checked) {
  background: #ecfdf5;
}

.project-name {
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  color: var(--accent);
  text-align: left;
}

.project-name:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.project-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.project-unit-select {
  width: 220px;
  max-width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  font: 600 13px "Segoe UI", sans-serif;
  color: var(--ink);
  cursor: pointer;
}

.project-unit-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 110, 91, 0.15);
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.draft {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn-border);
}

.badge.done {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

.empty {
  text-align: center;
  padding: 60px 24px;
}

.empty h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.empty p {
  color: var(--muted);
  line-height: 1.7;
  font-size: 14px;
}

/* ================= EDITOR VIEW & IMPORTANT HIGHLIGHTS ================= */
.editor-top {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.editor-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.edit-title {
  font-size: 23px;
  font-weight: 750;
  letter-spacing: -0.4px;
  margin: 0;
  color: var(--ink);
}

.editor-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

/* Highlight the "Kiểm tra nội dung / X điểm cần xem lại" button */
.issue-link {
  background: var(--warn-bg);
  border: 1.5px solid var(--warn-border);
  color: var(--warn);
  font-weight: 700;
}

.issue-link:hover:not(:disabled) {
  background: #fef3c7;
  border-color: #d97706;
  color: #92400e;
}

/* Highlight the Output Filename Bar */
.project-name-line {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 18px 0 22px;
  padding: 14px 20px;
  background: #ffffff;
  border: 1.5px solid var(--accent-border);
  border-left: 5px solid var(--accent);
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
}

.project-name-line label {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-hover);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.project-name-line input {
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  background: #f8fafc;
  min-width: 0;
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  transition: all 0.15s;
}

.project-name-line input:focus {
  background: #ffffff;
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 110, 91, 0.15);
}

/* Collapsible Form Groups (Khách hàng, Điện lực, Kỹ thuật, Thanh toán...) */
.form-group.card {
  border: 1.5px solid var(--line);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group.card[open] {
  border-color: var(--accent-border);
  box-shadow: var(--shadow);
}

.form-group > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: #f8fafc;
  user-select: none;
  transition: background 0.15s;
}

.form-group > summary:hover {
  background: #f0fdf9;
}

.form-group > summary::-webkit-details-marker {
  display: none;
}

.form-group > summary:before {
  content: "›";
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #e2e8f0;
  color: var(--ink-soft);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  transition: transform 0.18s ease, background 0.18s ease;
}

.form-group[open] > summary:before {
  transform: rotate(90deg);
  background: var(--accent);
  color: #ffffff;
}

.form-group[open] > summary {
  background: linear-gradient(90deg, var(--accent-light) 0%, #f8fafc 100%);
  color: var(--accent-hover);
  border-bottom: 1.5px solid var(--accent-border);
}

.form-group > summary > span {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: #ffffff;
  border: 1px solid var(--accent-border);
  padding: 3px 10px;
  border-radius: 999px;
  margin-left: auto;
}

/* Special prominence for Power Unit Group */
details[data-form-key$=":power-unit"] {
  border: 2px solid var(--accent);
}

details[data-form-key$=":power-unit"] > summary {
  background: linear-gradient(90deg, #dff6f0 0%, #f0fdf9 100%);
  color: var(--accent-hover);
}

/* Form Grid & Individual Fields */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 22px;
  padding: 22px;
  background: #ffffff;
}

.form-grid .field {
  margin: 0;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.field {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--line-soft);
  transition: all 0.15s ease;
}

.field:focus-within {
  background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 91, 0.14);
}

/* Highlight fields populated/modified from the old contract */
.field.changed {
  background: #f2fbf7;
  border: 1px solid #a7f3d0;
  border-left: 4px solid #10b981;
}

.field label, .simple-field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 700;
  margin-bottom: 8px;
}

.simple-field.changed > label::after {
  content: "Đã lọc / cập nhật";
  font-size: 10.5px;
  font-weight: 700;
  color: #047857;
  background: #d1fae5;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.field textarea, .field input, .dialog-input, .simple-field input {
  width: 100%;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.15s;
}

.simple-field textarea {
  padding: 9px 12px;
  min-height: 42px;
  font-size: 13.5px;
  font-weight: 500;
}

.field textarea:focus, .field input:focus, .simple-field input:focus, .grid textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Cover code boxes (Mã tỉnh, Mã loại HĐ, Số hợp đồng) */
input[data-code-pids] {
  font-family: Consolas, "Courier New", monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--accent-hover);
  background: #ffffff;
  border: 1.5px solid var(--accent-border);
}

.field .reset {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #ffffff;
  color: var(--muted);
}

/* Power Unit Selector inside Editor */
.unit-profile-select {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--accent-light);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
}

.unit-profile-select label {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-hover);
  white-space: nowrap;
}

.unit-profile-select select {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.unit-profile-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  justify-content: space-between;
  margin-top: 12px;
}

.unit-profile-actions .hint {
  max-width: 680px;
}

.unit-profile-actions button {
  flex-shrink: 0;
}

#powerUnitText {
  width: 100%;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.75;
  font: 13.5px/1.75 "Segoe UI", Arial, sans-serif;
  resize: vertical;
  background: #ffffff;
}

#powerUnitText:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 91, 0.14);
}

/* ================= TABLES VIEW (ĐO ĐẾM, GIÁ ĐIỆN, PHỤ LỤC) ================= */
.table-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #e2e8f0;
  padding: 6px;
  border-radius: 11px;
  margin: 0 0 20px;
}

.table-tabs > button:not(.table-undo) {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 20px;
  border-radius: 8px;
  box-shadow: none;
}

.table-tabs > button:not(.table-undo):hover {
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  transform: none;
}

.table-tabs > button.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(13, 110, 91, 0.3);
}

.table-tabs > button.active:hover {
  background: var(--accent-hover);
  color: #ffffff;
}

.table-tabs .table-undo {
  margin-left: auto;
  background: #ffffff;
}

.table-wrap {
  overflow: auto;
  padding: 0;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
  table-layout: fixed;
  font-size: 13px;
}

.grid td, .grid th {
  border: 1px solid var(--line);
  vertical-align: top;
  padding: 6px;
}

.grid tr:first-child td, .grid th.fixed-cell {
  background: #e6f4f1;
  color: var(--accent-hover);
  font-weight: 700;
  text-align: left;
  border-bottom: 2px solid var(--accent-border);
}

.grid .fixed-cell {
  padding: 12px 10px;
  white-space: pre-wrap;
  vertical-align: middle;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: #f8fafc;
}

.grid td:focus-within {
  background: #ecfdf5;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.grid textarea {
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  resize: vertical;
  min-height: 48px;
  padding: 6px 8px;
  line-height: 1.55;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
}

.grid textarea:focus {
  background: #ffffff;
}

.grid .row-actions {
  width: 96px;
  text-align: center;
  vertical-align: middle;
  background: #f8fafc;
}

.row-actions select {
  width: 100%;
  min-width: 76px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 7px 4px;
  background: #ffffff;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}

.row-actions select:hover, .row-actions select:focus {
  border-color: var(--accent);
  color: var(--accent);
}

.table-footer {
  padding: 14px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.field-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 4px 10px;
  border-radius: 999px;
}

/* ================= TOOLS MENU, SOURCE & CHECK VIEWS ================= */
.tools-menu {
  position: relative;
  flex-shrink: 0;
}

.tools-menu > summary {
  list-style: none;
  cursor: pointer;
  border: 1.5px solid var(--line);
  background: #f8fafc;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}

.tools-menu > summary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #ffffff;
}

.tools-menu > summary::-webkit-details-marker {
  display: none;
}

.tools-popover {
  position: absolute;
  right: 0;
  top: 44px;
  z-index: 8;
  min-width: 240px;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
}

.tools-popover button {
  display: block;
  width: 100%;
  border: 0;
  text-align: left;
  background: #ffffff;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 7px;
  white-space: nowrap;
  box-shadow: none;
}

.tools-popover button:hover {
  background: var(--accent-light);
  color: var(--accent-hover);
  transform: none;
}

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-left: 4px solid var(--warn);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 13px;
  line-height: 1.65;
  color: #92400e;
  margin-bottom: 20px;
}

.notice.info {
  background: #eff6ff;
  border-color: #bfdbfe;
  border-left: 4px solid #2563eb;
  color: #1e40af;
}

.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 12px 0;
}

.comparison pre {
  white-space: pre-wrap;
  font: 13px/1.65 "Segoe UI", sans-serif;
  background: #f8fafc;
  border: 1px solid var(--line-soft);
  padding: 14px;
  border-radius: 8px;
  margin: 6px 0;
}

.comparison .incoming {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.source-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.source-line {
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.source-line button {
  margin: 6px 0;
}

.issue {
  padding: 14px 18px;
  border: 1px solid var(--warn-border);
  border-left: 5px solid #d97706;
  border-radius: 8px;
  background: var(--warn-bg);
  margin-bottom: 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: #92400e;
  line-height: 1.65;
}

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

.link-button {
  color: var(--accent);
  border: 0;
  background: transparent;
  padding: 0;
  font-weight: 700;
  box-shadow: none;
}

.link-button:hover {
  background: transparent;
  text-decoration: underline;
  transform: none;
  box-shadow: none;
}

.storage-note {
  margin-top: 18px;
}

/* ================= DIALOGS & PREVIEW ================= */
dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 25px 90px rgba(15, 23, 42, 0.35);
  padding: 0;
  width: min(560px, 92vw);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.dialog-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line-soft);
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.dialog-head p {
  font-size: 12.5px;
  color: var(--muted);
  margin: 4px 0 0;
}

#dialogBody {
  padding: 24px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--line-soft);
}

.dialog-input {
  margin: 8px 0 14px;
}

#previewDialog {
  width: 94vw;
  height: 94vh;
  max-width: 1600px;
  max-height: 96vh;
}

#previewBody {
  height: calc(100% - 88px);
  overflow: auto;
  background: #cbd5e1;
}

.preview-canvas {
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

.preview-page {
  background: #ffffff;
  width: min(880px, 96%);
  box-shadow: 0 10px 35px rgba(15, 23, 42, 0.18);
  border-radius: 6px;
  padding: 52px 60px;
  font-family: "Times New Roman", Times, serif;
  font-size: 15px;
  line-height: 1.65;
  color: #111111;
}

.preview-sec-title {
  font-family: "Segoe UI", sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--accent-border);
  padding: 5px 12px;
  border-radius: 6px;
  margin: 24px 0 12px;
  display: inline-block;
}

.preview-p {
  margin: 0 0 8px;
  white-space: pre-wrap;
}

.preview-p.changed {
  background: #ecfdf5;
  border-left: 3.5px solid #10b981;
  padding: 2px 8px;
  border-radius: 0 4px 4px 0;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13.5px;
}

.preview-table td {
  border: 1px solid #333333;
  padding: 7px 9px;
  vertical-align: top;
  white-space: pre-wrap;
}

.preview-table tr.header-row td {
  font-weight: 700;
  background: #f1f5f9;
  text-align: center;
}

.delete-project-list {
  max-height: 220px;
  overflow: auto;
  padding-left: 24px;
  font-size: 13.5px;
  line-height: 1.8;
}

.loader {
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid #cbd5e1;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#toast {
  position: fixed;
  bottom: 26px;
  left: calc(50% + 100px);
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  font-weight: 500;
  padding: 13px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  max-width: 650px;
  font-size: 13.5px;
  transition: opacity 0.2s;
}

#toast.show {
  opacity: 1;
}

#toast.error {
  background: #b91c1c;
}

.batch-progress {
  padding: 18px 22px;
  border: 1.5px solid var(--accent-border);
  background: var(--accent-light);
  border-radius: 10px;
  margin-bottom: 20px;
  font-weight: 600;
  color: var(--accent-hover);
}

.mobile-tabs {
  display: none;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 1150px) {
  :root {
    --sidebar: 230px;
  }
  header {
    padding: 0 24px;
  }
  main {
    padding: 24px;
  }
  .header-title {
    max-width: 300px;
  }
  .header-actions button {
    padding: 9px 13px;
    font-size: 12.5px;
  }
  .save-state {
    display: none;
  }
  .projects td, .projects th {
    padding: 14px;
  }
}

@media (max-width: 760px) {
  :root {
    --sidebar: 0px;
  }
  .sidebar {
    display: none;
  }
  header {
    height: auto;
    min-height: 80px;
    flex-wrap: wrap;
    padding: 16px;
  }
  .header-title {
    max-width: 90vw;
  }
  .header-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  main {
    padding: 20px 14px;
  }
  .form-grid {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 14px;
  }
  .form-grid .wide {
    grid-column: auto;
  }
  .unit-profile-actions, .unit-profile-select {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }
  .mobile-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
  }
  .mobile-tabs button {
    font-size: 12.5px;
    padding: 8px 12px;
  }
  .mobile-tabs button.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
  }
  .editor-heading .edit-title {
    font-size: 20px;
  }
  .table-tabs > button:not(.table-undo) {
    padding: 8px 12px;
  }
  .projects {
    min-width: 620px;
  }
  .card {
    overflow: auto;
  }
  .comparison {
    grid-template-columns: 1fr;
  }
  #toast {
    left: 50%;
    width: 90%;
  }
}
