:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-strong: #eef3f3;
  --text: #1b2528;
  --muted: #657377;
  --line: #dce4e4;
  --primary: #006f6b;
  --primary-strong: #005854;
  --accent: #c84b31;
  --accent-strong: #ad3c26;
  --shadow: 0 18px 50px rgba(26, 43, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 20px clamp(14px, 3vw, 28px) 36px;
}

.topbar,
.toolbar,
.receiver-panel,
.call-panel,
.section-header,
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 16px;
}

.eyebrow,
.selected-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 4vw, 2.45rem);
  letter-spacing: 0;
}

.connection {
  min-width: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
  font-weight: 800;
}

.connection.is-online {
  color: var(--primary);
  border-color: rgba(0, 111, 107, 0.35);
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.tab,
.segment,
.receiver-floor,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.tab.is-active,
.segment.is-active,
.receiver-floor.is-active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(0, 111, 107, 0.18);
}

.view {
  display: none;
}

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

.toolbar,
.receiver-panel,
.unlock-panel,
.add-master,
.sender-step,
.assignment-panel,
.now-call,
.history-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.unlock-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.unlock-panel.is-hidden {
  display: none;
}

.sender-content.is-locked {
  display: none;
}

.field-group {
  display: grid;
  gap: 8px;
}

label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.segmented,
.actions-inline,
.pin-form,
.input-row {
  display: flex;
  gap: 8px;
}

.pin-form,
.input-row {
  align-items: stretch;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: #fff;
  font: inherit;
  font-weight: 800;
}

input:focus {
  outline: 3px solid rgba(0, 111, 107, 0.16);
  border-color: var(--primary);
}

.segment,
.receiver-floor {
  min-width: 88px;
  padding: 0 16px;
  background: var(--surface-strong);
}

.ghost-button {
  border: 1px solid var(--line);
  padding: 0 16px;
  background: var(--surface);
}

.primary-button {
  min-width: 92px;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 18px;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}

.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.add-master {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.sender-step {
  display: grid;
  gap: 10px;
}

.section-header.compact {
  margin-bottom: 0;
}

.section-header.compact .actions-inline {
  flex: 0 0 auto;
}

.assignment-panel {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 20px;
}

.assignment-list {
  display: grid;
  gap: 12px;
}

.assignment-row {
  display: grid;
  grid-template-columns: 86px 1fr 112px;
  gap: 10px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.assignment-master {
  display: grid;
  place-items: center;
  min-height: 76px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 1.35rem;
  font-weight: 900;
}

.assignment-task-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.task-button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface-strong);
  font-weight: 900;
}

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

.task-button:disabled {
  cursor: not-allowed;
  color: #9aa5a8;
  background: #f4f6f7;
}

.labor-button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-weight: 900;
}

.labor-button.is-active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.assignment-labor {
  min-width: 0;
}

.assignment-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
}

.master-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.master-button {
  width: 100%;
  aspect-ratio: 1.25;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  font-size: clamp(1.15rem, 5vw, 1.7rem);
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(27, 37, 40, 0.07);
}

.master-item {
  display: grid;
  gap: 6px;
}

.delete-master {
  min-height: 34px;
  border: 1px solid rgba(200, 75, 49, 0.28);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #fff7f4;
  font-size: 0.9rem;
  font-weight: 900;
}

.master-button.is-selected {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.call-panel {
  position: sticky;
  bottom: 0;
  z-index: 2;
  border-top: 1px solid var(--line);
  padding: 18px 0 0;
  background: linear-gradient(to top, var(--bg) 80%, rgba(244, 246, 247, 0));
}

.selected-text {
  margin-bottom: 0;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 900;
}

.call-preview {
  margin: 12px 0 0;
  color: var(--text);
  font-size: clamp(1.35rem, 5vw, 2rem);
  font-weight: 900;
  line-height: 1.5;
}

.call-button,
.voice-button {
  min-width: 140px;
  min-height: 58px;
  border-radius: 8px;
  color: #fff;
  background: #d92323;
  font-size: 1.1rem;
  font-weight: 900;
}

.call-button:disabled {
  cursor: not-allowed;
  background: #aeb9bb;
}

.voice-button {
  background: var(--primary);
}

.voice-button.is-enabled {
  background: var(--primary-strong);
}

.now-call {
  margin-top: 16px;
}

.now-call h2 {
  margin-bottom: 8px;
  font-size: clamp(1.55rem, 7vw, 3rem);
}

.now-call p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.history-section {
  margin-top: 18px;
}

.section-header {
  margin-bottom: 10px;
}

.section-header h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

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

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.history-title {
  display: block;
  margin-bottom: 4px;
}

.history-floor,
.history-item time,
.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state {
  margin: 0;
  padding: 10px 0;
}

.master-empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
}

@media (max-width: 620px) {
  .topbar,
  .toolbar,
  .receiver-panel,
  .call-panel,
  .section-header,
  .history-item {
    align-items: stretch;
    flex-direction: column;
  }

  .connection,
  .call-button,
  .voice-button,
  .primary-button,
  .labor-button {
    width: 100%;
  }

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

  .segmented,
  .actions-inline,
  .pin-form,
  .input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .pin-form input,
  .input-row input {
    grid-column: 1 / -1;
  }

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

  .assignment-master {
    min-height: 54px;
  }

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