:root {
  --bg: #eef7ff;
  --ink: #11283f;
  --muted: #5f7890;
  --panel: #ffffff;
  --line: #cde0f1;
  --coal: #0d4f86;
  --stone: #7ea5bf;
  --signal: #0e7cc3;
  --signal-weak: #d9edfb;
  --green: #16866d;
  --yellow: #e2a525;
  --blue: #216ba5;
  --danger: #d14b5a;
  --shadow: 0 18px 42px rgba(33, 107, 165, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(54, 158, 220, 0.18), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(238, 247, 255, 0.92)),
    var(--bg);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

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

button {
  cursor: pointer;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-view.is-hidden {
  display: none;
}

.login-panel {
  width: min(460px, 100%);
  padding: 22px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0 0 10px;
  color: var(--coal);
  font-size: 26px;
}

.login-panel p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.6;
}

.login-actions {
  display: grid;
  gap: 10px;
}

.login-message {
  min-height: 22px;
  margin-top: 14px;
  color: var(--danger);
  font-weight: 800;
}

.app-shell {
  min-height: 100vh;
  display: none;
  grid-template-columns: 260px minmax(0, 1fr) 310px;
}

.app-shell.is-authenticated {
  display: grid;
}

.sidebar,
.activity {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
}

.sidebar {
  background: linear-gradient(180deg, #0b5f9e, #0b78bd);
  color: #f8fcff;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
  display: block;
  margin-bottom: 28px;
}

.brand h1,
.topbar h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 20px;
}

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

.nav-button {
  width: 100%;
  padding: 13px 14px;
  color: #f8fcff;
  text-align: left;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
}

.nav-button.is-active,
.nav-button:hover {
  color: #074a76;
  background: #ffffff;
}

.main {
  padding: 22px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h2 {
  font-size: 29px;
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search-box {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.user-panel div {
  display: grid;
  gap: 2px;
}

.user-panel strong {
  color: var(--coal);
  font-size: 13px;
}

.user-panel span {
  color: var(--muted);
  font-size: 11px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 10px 11px;
  color: var(--ink);
  background: #f8fcff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

textarea {
  resize: vertical;
}

.primary-action,
.secondary-action {
  min-height: 42px;
  padding: 0 15px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-action {
  color: #ffffff;
  background: linear-gradient(180deg, #0f8bd6, #096ba8);
}

.secondary-action {
  color: var(--coal);
  background: #e8f3fb;
  border-color: var(--line);
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  padding: 14px;
  background: linear-gradient(180deg, #ffffff, #f6fbff);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
}

.span-2 {
  min-width: 0;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 68px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.delivery-list,
.queue-list,
.notification-log {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.delivery-item {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(150px, 0.65fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #f8fcff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.delivery-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
}

.delivery-title strong {
  font-size: 16px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  color: var(--muted);
  font-size: 12px;
}

.chip,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chip {
  color: #075184;
  background: #dff0fc;
}

.status.confirmed,
.status.completed {
  color: #fff;
  background: var(--green);
}

.status.pending,
.status.customer_checking {
  color: #4b3100;
  background: #ffd36a;
}

.status.price_requested,
.status.price_decided {
  color: #fff;
  background: var(--blue);
}

.status.lost,
.status.cancelled {
  color: #fff;
  background: var(--danger);
}

.sync-error {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: #ffffff;
  background: var(--danger);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
}

.item-actions button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--coal);
  background: #e8f3fb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 800;
}

.queue-card,
.notification-item {
  padding: 11px;
  background: #f8fcff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--signal);
  border-radius: var(--radius);
}

.queue-card p,
.notification-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.activity {
  background: rgba(255, 255, 255, 0.42);
  border-left: 1px solid var(--line);
}

.activity-panel {
  height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notification-log {
  overflow: auto;
}

.form-panel {
  max-width: 980px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: #e1f1fb;
  border-radius: var(--radius);
}

.segmented label {
  position: relative;
  overflow: hidden;
  min-width: 86px;
  min-height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 800;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  color: #fff;
  background: #0d75b4;
}

.form-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

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

.form-footer p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.settings-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.settings-body label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.settings-body p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.calendar-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 8px;
  overflow-x: auto;
}

.calendar-day {
  min-height: 160px;
  padding: 10px;
  background: #f8fcff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.calendar-day strong {
  display: block;
  margin-bottom: 8px;
}

.calendar-event {
  margin-top: 6px;
  padding: 7px;
  color: #fff;
  background: var(--green);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.35;
}

.detail-dialog {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.detail-dialog::backdrop {
  background: rgba(23, 32, 28, 0.55);
}

.detail-body {
  display: grid;
  gap: 12px;
}

.case-number {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.detail-fields div {
  padding: 10px;
  background: #f8fcff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.detail-fields span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .activity {
    position: static;
    grid-column: 1 / -1;
    height: auto;
    padding-top: 0;
  }

  .activity-panel {
    height: 300px;
  }
}

@media (max-width: 840px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    background: #f3f9ff;
  }

  .app-shell {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    flex-direction: column;
    overflow-x: hidden;
  }

  .app-shell.is-authenticated {
    display: flex;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    width: 100%;
    max-width: 100%;
    height: auto;
    padding: 10px 10px 9px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.96);
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 24px rgba(33, 107, 165, 0.12);
    backdrop-filter: blur(12px);
  }

  .brand {
    margin-bottom: 8px;
  }

  .brand h1 {
    color: var(--coal);
    font-size: 17px;
    line-height: 1.2;
  }

  .main {
    width: 100%;
    max-width: 100%;
    padding: 12px 10px 0;
    overflow-x: hidden;
  }

  .topbar {
    margin: 0 2px 10px;
  }

  .user-panel {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .user-panel .secondary-action {
    width: 100%;
  }

  .topbar h2 {
    font-size: 22px;
    line-height: 1.25;
  }

  .nav-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
    overflow-x: hidden;
    padding-bottom: 1px;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-button {
    width: auto;
    min-width: 0;
    min-height: 40px;
    padding: 0 4px;
    color: var(--coal);
    text-align: center;
    white-space: nowrap;
    background: #edf6fd;
    border-color: #d7e9f7;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
  }

  .nav-button.is-active,
  .nav-button:hover {
    color: #ffffff;
    background: #0d75b4;
    border-color: #0d75b4;
  }

  .topbar,
  .top-actions,
  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .view {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .view *,
  .sidebar *,
  .activity * {
    max-width: 100%;
  }

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

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .delivery-item {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
    background: #ffffff;
  }

  .delivery-title strong {
    width: 100%;
    font-size: 17px;
  }

  .meta {
    gap: 7px;
    font-size: 13px;
  }

  .item-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .item-actions button {
    width: 100%;
    min-height: 42px;
  }

  .panel-header {
    min-height: 0;
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .panel-header h3 {
    font-size: 18px;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(33, 107, 165, 0.11);
  }

  .segmented {
    width: 100%;
    padding: 3px;
    border-radius: 10px;
  }

  .segmented label {
    min-height: 46px;
    font-size: 16px;
    border-radius: 8px;
  }

  input,
  select,
  textarea,
  .primary-action,
  .secondary-action {
    min-height: 48px;
    font-size: 16px;
  }

  input,
  select,
  textarea {
    max-width: 100%;
    padding: 12px;
    background: #ffffff;
  }

  .form-panel {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .form-grid {
    width: 100%;
    min-width: 0;
    padding: 12px;
    gap: 11px;
  }

  .form-grid label {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    gap: 7px;
    color: #315f86;
    font-size: 13px;
  }

  .form-grid .wide {
    min-width: 0;
    max-width: 100%;
  }

  #receptionForm,
  #receptionView {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  #receptionForm * {
    max-width: 100%;
  }

  #receptionForm input,
  #receptionForm select,
  #receptionForm textarea {
    min-width: 0;
  }

  .form-footer {
    position: static;
    margin: 0;
    padding: 10px 12px 12px;
    background: #ffffff;
    border-radius: 0 0 10px 10px;
    box-shadow: none;
  }

  .form-footer p {
    font-size: 12px;
    line-height: 1.45;
  }

  .primary-action {
    width: 100%;
  }

  .calendar-grid {
    grid-template-columns: 1fr;
    overflow-x: visible;
    padding: 10px;
    gap: 10px;
  }

  .calendar-day {
    min-height: 88px;
    background: #ffffff;
  }

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

  .activity {
    width: 100%;
    max-width: 100%;
    position: static;
    height: auto;
    padding: 10px;
    background: transparent;
    border-left: 0;
  }

  .activity-panel {
    height: 220px;
  }

  .detail-dialog {
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
  }
}

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

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