:root {
  --tool-danger: #a52a2a;
  --tool-warning: #9a6300;
  --tool-success: #16845b;
  --tool-page-width: 1180px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--page);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.45;
}
button, input, select, textarea, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(242, 159, 5, .55); outline-offset: 3px; }

.tool-shell {
  width: min(var(--tool-page-width), 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + var(--telegram-ui-safe-top, var(--safe-top, 0px)))
    calc(16px + var(--safe-right, 0px))
    calc(34px + var(--safe-bottom, 0px))
    calc(16px + var(--safe-left, 0px));
}

.tool-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.tool-back, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 9px 12px;
  color: var(--brand);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
}
.save-indicator { color: var(--muted); font-size: .82rem; font-weight: 700; }

.tool-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
  padding: clamp(20px, 4vw, 34px);
  color: #fff;
  background: linear-gradient(135deg, var(--brand-strong), var(--brand));
  border-radius: 24px;
  box-shadow: 0 18px 42px rgba(15, 47, 72, .18);
}
.tool-kicker { margin: 0 0 6px; color: #cde0ec; font-size: .78rem; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.tool-hero h1 { margin: 0; color: #fff; font-size: clamp(1.7rem, 4vw, 2.65rem); line-height: 1.08; }
.tool-hero p { max-width: 760px; margin: 10px 0 0; color: #e5eff5; }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 15px;
  color: #fff;
  background: var(--brand);
  border: 1px solid transparent;
  border-radius: 13px;
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
}
.button.secondary { color: var(--brand); background: var(--brand-soft); border-color: #bfd6e4; }
.button.accent { color: var(--brand-strong); background: var(--accent); }
.button.ghost { color: #fff; background: rgba(255, 255, 255, .11); border-color: rgba(255, 255, 255, .35); }
.button.danger { color: var(--tool-danger); background: #fff2f0; border-color: #edc7c1; }
.button.small { min-height: 40px; padding: 8px 12px; font-size: .86rem; }
.button:disabled { cursor: not-allowed; opacity: .58; }

.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.panel {
  padding: clamp(16px, 3vw, 24px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 28px rgba(20, 54, 78, .06);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel h2, .panel h3 { margin: 0; color: var(--brand-strong); }
.panel h2 { font-size: 1.18rem; }
.panel h3 { font-size: 1rem; }
.panel-intro { margin: 5px 0 0; color: var(--muted); font-size: .88rem; }
.panel-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.field { grid-column: span 4; display: grid; gap: 6px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field.half { grid-column: span 6; }
.field label, .field-label { color: var(--brand-strong); font-size: .82rem; font-weight: 800; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #b8c9d4;
  border-radius: 11px;
}
.field textarea { min-height: 92px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: 2px solid rgba(242, 159, 5, .24); }
.field-error { min-height: 1.1em; color: var(--tool-danger); font-size: .76rem; }
.checkbox-field { display: flex; align-items: flex-start; gap: 9px; min-height: 44px; padding: 10px 12px; background: var(--brand-soft); border-radius: 11px; }
.checkbox-field input { width: 20px; height: 20px; margin: 1px 0 0; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.summary-card { padding: 14px; background: var(--brand-soft); border: 1px solid #c8dce8; border-radius: 15px; }
.summary-card strong { display: block; color: var(--brand-strong); font-size: 1.45rem; }
.summary-card span { color: var(--muted); font-size: .78rem; }
.summary-card.warning strong { color: var(--tool-warning); }
.summary-card.success strong { color: var(--tool-success); }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.toolbar .field { flex: 1 1 190px; display: grid; }
.record-list { display: grid; gap: 10px; }
.record-card {
  display: grid;
  gap: 11px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--brand);
  border-radius: 15px;
}
.record-card[data-status="closed"], .record-card[data-status="confirmed"], .record-card[data-status="on_time"], .record-card[data-status="removed_verified"] { border-left-color: var(--tool-success); }
.record-card[data-status="overdue"], .record-card[data-status="late"] { border-left-color: var(--tool-danger); }
.record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.record-title { margin: 0; color: var(--brand-strong); font-size: 1rem; }
.record-meta { display: flex; flex-wrap: wrap; gap: 7px; color: var(--muted); font-size: .78rem; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: .72rem; font-weight: 800; }
.badge.success { color: var(--tool-success); background: #e7f6ef; }
.badge.warning { color: var(--tool-warning); background: #fff4d6; }
.badge.danger { color: var(--tool-danger); background: #fff0ee; }
.record-details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.detail { min-width: 0; padding: 10px; background: #f7fafc; border-radius: 10px; }
.detail-label { display: block; color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.detail-value { display: block; margin-top: 3px; overflow-wrap: anywhere; }
.record-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.empty-state { padding: 30px 16px; color: var(--muted); text-align: center; border: 1px dashed #b8c9d4; border-radius: 15px; }
.empty-state strong { display: block; margin-bottom: 6px; color: var(--brand-strong); }

.notice { margin: 0; padding: 12px 14px; color: var(--muted); background: #f7fafc; border-radius: 12px; font-size: .84rem; }
.status-line { min-height: 1.35em; margin: 9px 0 0; color: var(--brand); font-size: .83rem; font-weight: 800; }
.status-line.error { color: var(--tool-danger); }
.status-line.success { color: var(--tool-success); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--telegram-ui-safe-top, 0px)) calc(16px + var(--safe-right, 0px)) calc(16px + var(--safe-bottom, 0px)) calc(16px + var(--safe-left, 0px));
  background: rgba(15, 47, 72, .55);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 32px - var(--telegram-ui-safe-top, 0px));
  overflow: auto;
  padding: 20px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(15, 47, 72, .35);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.modal h2 { margin: 0; color: var(--brand-strong); font-size: 1.25rem; }
.modal-close { width: 44px; height: 44px; padding: 0; color: var(--brand); background: var(--brand-soft); border: 0; border-radius: 12px; font-size: 1.35rem; cursor: pointer; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; margin-top: 16px; }

.data-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
.data-table { width: 100%; min-width: 820px; border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { color: #fff; background: var(--brand); font-size: .76rem; }
.data-table td { font-size: .82rem; }
.data-table tr:last-child td { border-bottom: 0; }

.tool-footer { margin-top: 16px; color: var(--muted); font-size: .78rem; text-align: center; }

@media (max-width: 760px) {
  .tool-hero { grid-template-columns: 1fr; }
  .hero-actions { justify-content: flex-start; }
  .hero-actions .button { flex: 1 1 150px; }
  .field, .field.half { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .record-details { grid-template-columns: 1fr; }
  .panel-head { display: grid; }
  .panel-actions { justify-content: flex-start; }
  .record-head { display: grid; }
  .record-actions { justify-content: flex-start; }
}

@media (max-width: 430px) {
  .tool-shell { padding-left: calc(10px + var(--safe-left, 0px)); padding-right: calc(10px + var(--safe-right, 0px)); }
  .tool-hero, .panel { border-radius: 17px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .button { width: 100%; }
  .tool-topbar .tool-back, .tool-topbar .icon-button { width: auto; }
  .modal { padding: 16px; }
}

@media print {
  body { background: #fff; }
  .tool-shell { width: 100%; padding: 0; }
  .tool-topbar, .hero-actions, .panel-actions, .toolbar, .record-actions, .tool-footer { display: none !important; }
  .tool-hero { color: #000; background: #fff; border: 1px solid #999; box-shadow: none; }
  .tool-hero h1, .tool-hero p, .tool-kicker { color: #000; }
  .panel, .record-card { box-shadow: none; break-inside: avoid; }
}
