:root {
  --bg-top: #e7edf4;
  --bg-bottom: #f6f8fb;
  --card-bg: #ffffff;
  --text: #1b2a3a;
  --muted: #5a697a;
  --line: #cbd6e2;
  --brand: #174a7a;
  --brand-dark: #11395f;
  --danger-bg: #fdecec;
  --danger-text: #7a1f24;
  --danger-border: #f2c6c9;
  --success-bg: #eaf7ef;
  --success-text: #1f5a32;
  --success-border: #bfe3cb;
  --shadow: 0 14px 34px rgba(17, 37, 61, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html.signature-pad-active,
body.signature-pad-active {
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", "Noto Sans", "Helvetica Neue", sans-serif;
  line-height: 1.45;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  min-height: 100vh;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
  line-height: 1.25;
}

h2 {
  font-size: 1.05rem;
}

.page-wrap {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 1rem 0.85rem 2rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid rgba(148, 167, 191, 0.35);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.card-compact {
  max-width: 540px;
  margin: 0 auto;
}

.section-head {
  margin-bottom: 1rem;
}

.trip-line {
  margin-top: 0.3rem;
  color: var(--brand);
  font-weight: 600;
}

.meta-grid {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.meta-grid div {
  background: #f4f7fa;
  border: 1px solid #d9e2ed;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}

.meta-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.meta-value {
  display: block;
  margin-top: 0.1rem;
  font-weight: 600;
}

.form-stack {
  display: grid;
  gap: 0.95rem;
}

.documents-panel {
  margin-bottom: 1rem;
  border: 1px solid #d8e2ee;
  border-radius: 12px;
  background: #f7fafd;
  padding: 0.85rem;
}

.documents-panel-head p {
  margin-top: 0.3rem;
}

.documents-panel .doc-list {
  margin-top: 0.75rem;
}

.documents-panel .doc-item {
  background: #fff;
}

.field-grid {
  display: grid;
  gap: 0.85rem;
}

.page-actions {
  margin-top: 0.85rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.button-row {
  display: grid;
  gap: 0.55rem;
}

label,
legend {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
  display: inline-block;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid transparent;
  border-color: #7da4cc;
  box-shadow: 0 0 0 3px rgba(56, 123, 192, 0.22);
}

textarea {
  resize: vertical;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.checkboxes {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0;
  padding: 0.7rem 0.8rem;
}

.checkbox-line {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-weight: 400;
  margin-top: 0.45rem;
}

.checkbox-line input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.15rem;
  flex: 0 0 auto;
}

.checkbox-line span {
  flex: 1;
}

.signature-box {
  border: 1px dashed #8da3b8;
  border-radius: 12px;
  padding: 0.8rem;
  background: #f8fafc;
}

.signature-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.signature-canvas {
  margin-top: 0.6rem;
  width: 100%;
  height: 220px;
  background: #fff;
  border: 1px solid #9eb2c7;
  touch-action: none;
  -ms-touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 10px;
}

.signature-error {
  margin-top: 0.45rem;
  color: var(--danger-text);
  font-weight: 600;
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-secondary {
  background: #e7edf4;
  color: #1d344d;
}

.btn-secondary:hover {
  background: #d8e2ee;
}

.btn-small {
  padding: 0.48rem 0.65rem;
  font-size: 0.85rem;
}

.alert {
  padding: 0.72rem 0.8rem;
  border-radius: 10px;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

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

.hint {
  margin-top: 0.9rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.summary-list {
  margin: 1rem 0;
  display: grid;
  gap: 0.5rem;
}

.summary-list div {
  border: 1px solid #dde6ef;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #f8fafd;
}

.summary-list dt {
  color: var(--muted);
  font-size: 0.86rem;
}

.summary-list dd {
  margin: 0.1rem 0 0;
  font-weight: 600;
}

.admin-header {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
}

.admin-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.admin-block {
  margin-top: 1.3rem;
}

.admin-block-head {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid #dde6ef;
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
  background: #fff;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.62rem 0.68rem;
  border-bottom: 1px solid #ecf1f7;
  vertical-align: middle;
}

.data-table thead th {
  background: #f3f7fb;
  color: #2b4057;
  font-size: 0.9rem;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.table-empty {
  color: var(--muted);
  font-style: italic;
}

.doc-list {
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.doc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
  border: 1px solid #dde6ef;
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
  background: #f8fafd;
}

.doc-name {
  display: block;
  overflow-wrap: anywhere;
}

.doc-meta {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.doc-category {
  display: inline-block;
  border: 1px solid #c4d3e4;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #2b4f73;
  background: #edf3f9;
}

.doc-group-list {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.55rem;
}

.doc-group {
  border: 1px solid #d6e2ef;
  border-radius: 10px;
  background: #fff;
  padding: 0.3rem 0.55rem 0.55rem;
}

.doc-group > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-weight: 600;
  padding: 0.42rem 0;
}

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

.doc-count {
  min-width: 1.6rem;
  padding: 0.1rem 0.4rem;
  text-align: center;
  border-radius: 999px;
  background: #e7eef6;
  color: #24476b;
  font-size: 0.78rem;
  font-weight: 700;
}

.doc-empty {
  border: 1px dashed #c6d4e3;
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
  color: var(--muted);
  background: #fbfcfe;
}

.chat-board {
  margin-top: 1rem;
  border: 1px solid #d8e3ef;
  border-radius: 12px;
  background: #f7fafd;
  padding: 0.75rem;
}

.chat-status {
  margin: 0;
  font-size: 0.88rem;
}

.chat-status-error {
  color: var(--danger-text);
}

.chat-messages {
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
  max-height: 340px;
  overflow-y: auto;
  display: grid;
  gap: 0.5rem;
}

.chat-item {
  border: 1px solid #d9e4ef;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: #fff;
}

.chat-item-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.chat-author {
  color: #123b63;
  overflow-wrap: anywhere;
}

.chat-time {
  color: var(--muted);
  font-size: 0.8rem;
  flex: 0 0 auto;
}

.chat-message {
  margin: 0.35rem 0 0;
  overflow-wrap: anywhere;
}

.chat-empty {
  border: 1px dashed #c7d5e5;
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  color: var(--muted);
  background: #fbfcfe;
}

.chat-form {
  margin-top: 1rem;
}

.chat-counter {
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.is-disabled {
  opacity: 0.75;
  pointer-events: none;
}

@media (min-width: 700px) {
  .page-wrap {
    padding: 2rem 1.3rem 3rem;
  }

  .card {
    padding: 1.4rem;
  }

  .field-grid {
    grid-template-columns: 1fr 1fr;
  }

  .button-row {
    grid-template-columns: auto auto;
    justify-content: start;
  }

  .chat-messages {
    max-height: 420px;
  }

  h1 {
    font-size: 1.65rem;
  }
}
