* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f8fafc;
  color: #0f172a;
}

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

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px 1fr;
}

.sidebar {
  background: #fff;
  border-right: 1px solid #e2e8f0;
  padding: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #0f172a;
  color: #fff;
  font-weight: 900;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: #64748b;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  width: 100%;
  text-align: left;
  border-radius: 16px;
  padding: 13px 14px;
  background: transparent;
  color: #475569;
  font-size: 14px;
  font-weight: 800;
}

.nav-item.active {
  background: #0f172a;
  color: #fff;
}

.nav-item:not(.active):hover {
  background: #f1f5f9;
}

.main {
  padding: 28px;
}

.header {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 28px;
  padding: 24px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
  box-shadow: 0 10px 35px rgba(15, 23, 42, .05);
}

.kicker {
  margin: 0 0 8px;
  color: #047857;
  font-size: 13px;
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 36px);
  letter-spacing: -.05em;
  line-height: 1.15;
}

.lead {
  margin: 10px 0 0;
  color: #64748b;
  line-height: 1.8;
  font-size: 14px;
}

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

.btn {
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  font-weight: 900;
  cursor: pointer;
}

.btn-primary {
  background: #059669;
  color: #fff;
}

.btn-dark {
  background: #0f172a;
  color: #fff;
}

.btn-light {
  background: #f1f5f9;
  color: #0f172a;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .04);
}

.stat-label {
  margin: 0;
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
}

.stat-value {
  margin: 8px 0 0;
  font-size: 30px;
  font-weight: 950;
  letter-spacing: -.04em;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 20px;
}

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 28px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .04);
  margin-bottom: 20px;
}

.card-title {
  margin: 0;
  font-size: 19px;
  font-weight: 950;
}

.card-sub {
  margin: 6px 0 18px;
  color: #64748b;
  line-height: 1.7;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field.full {
  grid-column: 1 / -1;
}

.label {
  color: #334155;
  font-size: 13px;
  font-weight: 900;
}

.required {
  margin-left: 5px;
  color: #dc2626;
  font-size: 11px;
  font-weight: 950;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 16px;
  padding: 12px 14px;
  outline: none;
}

.textarea {
  min-height: 110px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 4px #d1fae5;
}

.preview {
  background: #f8fafc;
  border-radius: 22px;
  padding: 18px;
}

.preview-label {
  margin: 0;
  color: #64748b;
  font-size: 12px;
  font-weight: 900;
}

.preview-main {
  margin: 6px 0 0;
  font-size: 22px;
  font-weight: 950;
}

.badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  background: #ecfdf5;
  color: #047857;
  font-size: 12px;
  font-weight: 900;
}

.badge.dark {
  background: #0f172a;
  color: #fff;
}

.facility-list {
  display: grid;
  gap: 10px;
}

.facility-item {
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 14px;
}

.facility-name {
  margin: 0;
  font-weight: 950;
}

.facility-meta {
  margin: 5px 0 0;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.item-bottom {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.small-chip {
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 900;
}

.mobile-top {
  display: none;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-top {
    display: block;
    margin-bottom: 14px;
  }

  .main {
    padding: 16px;
  }

  .header {
    display: block;
    border-radius: 24px;
  }

  .actions {
    margin-top: 16px;
  }

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

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

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

/* === mobile operation upgrade === */
.collapse-head {
  width: 100%;
  border: 0;
  background: transparent;
  color: #0f172a;
  padding: 0;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 19px;
  font-weight: 950;
  text-align: left;
  cursor: pointer;
}

.collapse-state {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
}

.card.is-collapsed > :not(.collapse-head):not(.card-title) {
  display: none;
}

.field.invalid .input,
.field.invalid .select,
.field.invalid .textarea {
  border-color: #ef4444;
  box-shadow: 0 0 0 4px #fee2e2;
}

.field-error {
  color: #dc2626;
  font-size: 12px;
  font-weight: 800;
}

.mobile-actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: none;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .94);
  border-top: 1px solid #e2e8f0;
  backdrop-filter: blur(14px);
  box-shadow: 0 -10px 30px rgba(15, 23, 42, .08);
}

.mobile-actionbar .btn {
  flex: 1;
  min-height: 48px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 60;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 28px));
  border-radius: 18px;
  padding: 14px 16px;
  background: #0f172a;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 15px 45px rgba(15, 23, 42, .25);
  display: none;
}

.toast.show {
  display: block;
}

.empty-result {
  display: none;
  color: #64748b;
  background: #f8fafc;
  border-radius: 16px;
  padding: 14px;
  font-size: 13px;
  font-weight: 800;
}

.empty-result.show {
  display: block;
}

@media (max-width: 980px) {
  body {
    padding-bottom: 86px;
  }

  .mobile-actionbar {
    display: flex;
  }

  .header .actions {
    display: none;
  }
}

.zip-message {
  margin-top: 6px;
  min-height: 18px;
  font-size: 12px;
  font-weight: 800;
  color: #64748b;
}

.zip-message[data-type="loading"] {
  color: #0369a1;
}

.zip-message[data-type="success"] {
  color: #047857;
}

.zip-message[data-type="error"] {
  color: #b91c1c;
}

/* === name + kana layout polish === */
.name-kana-pair {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  border: 1px solid #e8eef5;
  border-radius: 20px;
  background: #fbfdff;
}

.name-kana-pair .field {
  margin: 0;
}

.name-kana-pair .label {
  color: #1e293b;
}

.name-kana-pair .input {
  background: #ffffff;
}

.form-grid .field {
  min-width: 0;
}

.card {
  overflow: hidden;
}

.card-title {
  letter-spacing: -0.02em;
}

.card-sub {
  margin-bottom: 18px;
}

@media (max-width: 980px) {
  .name-kana-pair {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
}

/* === facility type position polish === */
.facility-type-priority {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid #e8eef5;
  border-radius: 20px;
  background: #fbfdff;
}

.facility-type-priority .select {
  background: #ffffff;
}

/* === organization type / postal layout polish === */
.organization-type-priority,
.facility-type-priority,
.postal-address-pair {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid #e8eef5;
  border-radius: 20px;
  background: #fbfdff;
}

.postal-address-pair {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
}

.organization-type-priority .select,
.facility-type-priority .select,
.postal-address-pair .input {
  background: #ffffff;
}

@media (max-width: 980px) {
  .postal-address-pair {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
}

/* === fix postal / address box balance === */
.postal-address-pair {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr !important;
  gap: 14px;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}

.postal-address-pair .field {
  margin: 0;
}

.postal-address-pair .input {
  width: 100%;
  background: #ffffff;
}

@media (max-width: 980px) {
  .postal-address-pair {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
}

/* === organization phone / email layout polish === */
.phone-email-pair {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.phone-email-pair .field {
  margin: 0;
}

@media (max-width: 980px) {
  .phone-email-pair {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* === final postal / address size fix === */
.postal-address-pair {
  grid-column: 1 / -1;
  display: grid !important;
  grid-template-columns: 180px minmax(0, 1fr) !important;
  gap: 14px !important;
  align-items: start !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}

.postal-address-pair .field {
  margin: 0 !important;
  min-width: 0;
}

.postal-address-pair .input {
  width: 100%;
  min-height: 46px;
  height: 46px;
  background: #ffffff;
}

.postal-address-pair + .zip-message {
  grid-column: 1 / -1;
  margin-top: -4px;
  margin-bottom: 2px;
  padding-left: 2px;
}

@media (max-width: 980px) {
  .postal-address-pair {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .postal-address-pair .input {
    height: 48px;
  }
}

/* MEDILINK_ACTION_BUTTON_SPACING */
.facility-item .item-bottom {
  margin-bottom: 10px;
}

.facility-item .item-bottom + a.btn,
.facility-item .item-bottom + .btn,
.facility-item a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  margin-top: 12px;
  line-height: 1.2;
  clear: both;
}

.facility-item .btn + .btn {
  margin-left: 8px;
}

@media (max-width: 640px) {
  .facility-item a.btn,
  .facility-item .btn {
    width: 100%;
    margin-left: 0;
  }
}

/* MEDILINK_HEADER_BUTTON_BALANCE */
.header {
  align-items: center;
  gap: 18px;
}

.header > .btn,
.header > a.btn,
.header > button.btn,
.header .no-print > .btn,
.header .no-print > a.btn,
.header .no-print > button.btn {
  width: auto !important;
  min-width: 118px !important;
  max-width: 220px !important;
  height: 44px !important;
  min-height: 44px !important;
  padding: 0 18px !important;
  border-radius: 14px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1.2 !important;
  white-space: nowrap !important;
  font-size: 14px !important;
}

.header > .btn.btn-primary,
.header > a.btn.btn-primary,
.header > button.btn.btn-primary {
  box-shadow: none;
}

@media (max-width: 760px) {
  .header {
    align-items: stretch;
  }

  .header > .btn,
  .header > a.btn,
  .header > button.btn,
  .header .no-print > .btn,
  .header .no-print > a.btn,
  .header .no-print > button.btn {
    width: 100% !important;
    max-width: none !important;
  }
}

/* MEDILINK_ROLE_THEME_FACILITY */
:root {
  --role-main: #064e3b;
  --role-main-2: #065f46;
  --role-accent: #10b981;
  --role-accent-soft: #ecfdf5;
  --role-border: #a7f3d0;
}

body {
  background:
    radial-gradient(circle at top right, rgba(16,185,129,.14), transparent 34%),
    linear-gradient(180deg, #f8fffb 0%, #eefbf5 100%);
}

.sidebar {
  background: linear-gradient(180deg, #022c22 0%, #065f46 100%) !important;
}

.brand-mark {
  background: linear-gradient(135deg, #34d399, #059669) !important;
  color: #fff !important;
  box-shadow: 0 12px 30px rgba(16,185,129,.28);
}

.brand-title,
.brand-sub {
  color: #fff !important;
}

.nav-item {
  color: rgba(255,255,255,.78) !important;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(16,185,129,.20) !important;
  color: #fff !important;
  border-color: rgba(167,243,208,.42) !important;
}

.kicker {
  color: #047857 !important;
}

.btn-primary {
  background: linear-gradient(135deg, #047857, #10b981) !important;
  border-color: #10b981 !important;
  color: #fff !important;
}

.stat,
.card {
  border-color: rgba(16,185,129,.18) !important;
}

.stat-value {
  color: #047857 !important;
}

.small-chip {
  background: #ecfdf5 !important;
  color: #047857 !important;
  border-color: #a7f3d0 !important;
}

.notice-card {
  background: linear-gradient(135deg, #ecfdf5, #ffffff) !important;
  border-color: #10b981 !important;
}

/* MEDILINK_BRAND_BY_SEED */
.brand-title {
  font-size: 15px !important;
  letter-spacing: .02em !important;
  line-height: 1.2 !important;
  white-space: nowrap !important;
}

.brand .brand-sub {
  display: none !important;
}

/* MEDILINK_LOGIN_BRAND_POLISH */
.login-card .brand-title,
.login-panel .brand-title,
.auth-card .brand-title,
.brand-title {
  white-space: nowrap;
}

.login-card h1,
.login-panel h1,
.auth-card h1 {
  letter-spacing: .02em;
}

.login-card .brand-sub,
.login-panel .brand-sub,
.auth-card .brand-sub {
  font-weight: 700;
  opacity: .82;
}
