:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: rgba(255, 255, 255, 0.92);
  --text: #172026;
  --muted: #63717c;
  --line: #dbe2e7;
  --primary: #126b62;
  --primary-dark: #0b504a;
  --accent: #b35a1f;
  --danger: #a93434;
  --ok: #1f7a44;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(245, 247, 248, 0.52), rgba(245, 247, 248, 0.88) 48%, rgba(245, 247, 248, 0.96)),
    url("/assets/hospital-background.png") center top / cover fixed,
    var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand strong {
  font-size: 18px;
}

.brand span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav a,
button,
.button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  font-size: 14px;
  text-decoration: none;
}

button.primary,
.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover,
.button.primary:hover {
  background: var(--primary-dark);
}

button.danger {
  color: var(--danger);
}

.main {
  width: min(1120px, calc(100vw - 32px));
  margin: 28px auto 48px;
}

.grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 16px 48px rgba(23, 32, 38, 0.12);
  backdrop-filter: blur(12px);
}

.panel h1,
.panel h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

.panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

label {
  color: #334049;
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.94);
  font: inherit;
  min-height: 40px;
  padding: 9px 11px;
}

textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.5;
}

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

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  background: rgba(249, 251, 251, 0.94);
  padding: 12px;
  color: #26343c;
  margin: 14px 0;
}

.notice.error {
  border-left-color: var(--danger);
}

.notice.success {
  border-left-color: var(--ok);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.94);
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #eef3f4;
  color: #2d3b43;
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  padding: 4px 9px;
  font-size: 12px;
  background: #eef3f4;
  color: #394852;
}

.status.archived {
  background: #e8f4ed;
  color: var(--ok);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.swap-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.record-content {
  max-width: 420px;
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  body {
    background:
      linear-gradient(180deg, rgba(245, 247, 248, 0.66), rgba(245, 247, 248, 0.94)),
      url("/assets/hospital-background.png") center top / auto 340px no-repeat,
      var(--bg);
  }

  .topbar {
    height: auto;
    padding: 14px 16px;
    align-items: flex-start;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .main {
    width: calc(100vw - 24px);
    margin-top: 18px;
  }

  .grid,
  .toolbar,
  .swap-toolbar {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 16px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      12px
      max(12px, env(safe-area-inset-left));
    gap: 10px;
  }

  .brand strong {
    font-size: 16px;
    line-height: 1.25;
  }

  .brand span,
  .muted {
    font-size: 12px;
    line-height: 1.5;
  }

  .nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  }

  .nav a,
  .nav button,
  .actions button,
  .button {
    min-height: 46px;
    width: 100%;
  }

  button,
  .button {
    min-height: 44px;
    font-size: 15px;
  }

  .main {
    width: 100%;
    margin: 0 auto 28px;
    padding: 12px;
  }

  .login-page .main {
    min-height: calc(100vh - 82px);
    display: grid;
    align-content: start;
  }

  .login-page .grid {
    max-width: 440px;
    width: 100%;
    margin: 0 auto;
  }

  .panel {
    padding: 14px;
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(23, 32, 38, 0.11);
  }

  .panel h1,
  .panel h2 {
    font-size: 18px;
    line-height: 1.3;
    margin-bottom: 14px;
  }

  .field {
    margin-bottom: 12px;
  }

  label {
    font-size: 13px;
  }

  input,
  select,
  textarea {
    min-height: 46px;
    border-radius: 8px;
    font-size: 16px;
    padding: 10px 12px;
  }

  textarea {
    min-height: 152px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .toolbar,
  .swap-toolbar {
    gap: 8px;
  }

  .notice {
    margin: 12px 0;
    font-size: 14px;
    line-height: 1.5;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  table {
    min-width: 0;
    background: transparent;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    display: grid;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(72px, 0.34fr) 1fr;
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    padding: 9px 10px;
    font-size: 14px;
    line-height: 1.45;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  td:empty::after {
    content: "-";
    color: var(--muted);
  }

  td input,
  td select {
    min-height: 42px;
  }

  .record-content {
    max-width: none;
  }
}
