:root {
  --bg: #f0f4f8;
  --card: #fff;
  --text: #1a2b3c;
  --muted: #5c6b7a;
  --border: #d8e2ec;
  --primary: #0d6e6e;
  --primary-hover: #0a5858;
  --accent: #e85d4c;
  --rate-low: #2e9b6a;
  --rate-mid: #d4a017;
  --rate-high: #e85d4c;
  --shadow: 0 2px 12px rgba(26, 43, 60, 0.08);
  --radius: 12px;
  --font: "IBM Plex Sans KR", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.visits {
  display: flex;
  gap: 0.5rem;
}

.visit-pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.visit-pill strong {
  color: var(--text);
  margin-right: 0.15rem;
}

.visit-pill.today strong {
  color: var(--primary);
}

.sync-pill {
  background: #eef6f6;
  border: 1px solid #b8d8d8;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.sync-pill.sync-ok {
  background: #e6f6ee;
  border-color: #9fd4b8;
  color: #1a6b42;
}

.sync-pill.sync-err {
  background: #fff6e0;
  border-color: #e8c96a;
  color: #8a6a00;
}

.mirror-banner {
  background: #e8f4fc;
  border: 1px solid #9ecae8;
  color: #1a5276;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 500;
}

.mirror-mode .room-readonly input,
.mirror-mode .room-readonly select,
.mirror-mode .pi-readonly input,
.mirror-mode .pi-readonly select {
  background: #f5f8fa;
  border-color: #e2e8ef;
}

.mirror-mode .pi-readonly .team-tabs {
  display: none;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: #f5f9fc;
  border-color: #b8c9d8;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.species-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 720px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .app {
    padding: 0.75rem 0.65rem 2.5rem;
  }

  .card {
    padding: 1rem 0.85rem;
  }

  .brand h1 {
    font-size: 1.2rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .btn,
  .toolbar .file-btn {
    width: 100%;
    justify-content: center;
    min-height: 2.75rem;
  }

  .kpi-value {
    font-size: 1.45rem;
  }

  .species-tab {
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
  }

  .sector-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.45rem;
    padding-bottom: 0.35rem;
    position: static;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .sector-nav::-webkit-scrollbar {
    display: none;
  }

  .sector-nav-title {
    display: none;
  }

  .sector-btn {
    flex: 0 0 auto;
    min-width: 7.5rem;
    font-size: 0.78rem;
    padding: 0.6rem 0.75rem;
  }

  .sector-rooms-head {
    font-size: 0.85rem;
  }

  .room-table {
    display: block;
    font-size: 0.85rem;
  }

  .room-table thead {
    display: none;
  }

  .room-table tbody {
    display: block;
  }

  .room-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 0.65rem;
    padding: 0.85rem 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .room-table td {
    display: block;
    padding: 0;
    border: none;
  }

  .room-table td:first-child {
    grid-column: 1 / -1;
  }

  .room-table td:last-child {
    grid-column: 1 / -1;
  }

  .room-table td:nth-child(1)::before {
    content: "호실";
  }

  .room-table td:nth-child(2)::before {
    content: "총 케이지";
  }

  .room-table td:nth-child(3)::before {
    content: "기사용";
  }

  .room-table td:nth-child(4)::before {
    content: "미사용";
  }

  .room-table td:nth-child(5)::before {
    content: "가동률";
  }

  .room-table td:nth-child(n + 2):not(:last-child)::before {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.2rem;
  }

  .room-table input,
  .room-table select {
    max-width: none;
    font-size: 0.9rem;
    padding: 0.45rem 0.55rem;
  }

  .room-table .btn {
    width: 100%;
    min-height: 2.5rem;
  }

  .pi-row {
    grid-template-columns: 1fr;
  }

  .pi-team-input {
    max-width: none;
  }

  .team-tab {
    font-size: 0.75rem;
    padding: 0.35rem 0.6rem;
  }

  .memo-author-field input {
    max-width: none;
  }

  .memo-form-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .memo-form-foot .btn {
    width: 100%;
    min-height: 2.75rem;
  }

  .attach-hint {
    flex: 1 1 100%;
  }
}

.kpi {
  background: #f7fafc;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
}

.kpi-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-value small {
  font-size: 0.9rem;
  font-weight: 500;
  margin-left: 0.1rem;
}

.kpi-value.accent {
  color: var(--accent);
}

.kpi-value.rate {
  color: var(--primary);
}

.species-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.species-tab {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  color: var(--muted);
}

.species-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.species-tab .count {
  opacity: 0.85;
  margin-left: 0.15rem;
}

.room-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.rooms-layout {
  display: grid;
  grid-template-columns: minmax(148px, 200px) 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 720px) {
  .rooms-layout {
    grid-template-columns: 1fr;
  }
}

.sector-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: sticky;
  top: 0.5rem;
}

.sector-nav-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 0.25rem 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sector-btn {
  font-family: inherit;
  font-size: 0.82rem;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  color: var(--text);
  line-height: 1.35;
}

.sector-btn:hover {
  border-color: var(--primary);
  background: #f5fafb;
}

.sector-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.sector-btn .sector-meta {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 0.15rem;
}

.sector-btn.active .sector-meta {
  opacity: 0.92;
}

.sector-rooms-head {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.room-sub-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: 0.15rem;
}

.room-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.room-table th,
.room-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.room-table th {
  background: #f0f6fa;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
}

.room-table input,
.room-table select {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  max-width: 120px;
}

.room-table input.wide {
  max-width: 100%;
}

.rate-badge {
  display: inline-block;
  min-width: 3rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  text-align: center;
}

.rate-badge.low {
  background: #e6f6ee;
  color: var(--rate-low);
}

.rate-badge.mid {
  background: #fff6e0;
  color: var(--rate-mid);
}

.rate-badge.high {
  background: #fdecea;
  color: var(--rate-high);
}

.pi-collapse {
  background: #fafcfe;
  border-top: 1px solid var(--border);
}

.pi-collapse > summary {
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  user-select: none;
}

.pi-collapse > summary::-webkit-details-marker {
  display: none;
}

.pi-collapse > summary::after {
  content: "▼";
  font-size: 0.7rem;
  color: var(--muted);
  transition: transform 0.15s;
}

.pi-collapse:not([open]) > summary::after {
  transform: rotate(-90deg);
}

.pi-collapse .pi-meta {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.pi-collapse-body {
  padding: 0 1.25rem 1rem;
}

.pi-row {
  display: grid;
  grid-template-columns: 1fr 1fr 72px 1fr 130px 56px auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
  padding: 0.65rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pi-row-team {
  grid-column: 1 / -1;
}

.team-picker-label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.team-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}

.team-tab {
  font-family: inherit;
  font-size: 0.72rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  color: var(--muted);
}

.team-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.team-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.pi-team-input {
  width: 100%;
  max-width: 320px;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.pi-lmo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.pi-lmo input {
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
}

.room-inuse-val {
  font-weight: 600;
  color: var(--accent);
}

.kpi-note {
  font-size: 0.75rem;
  color: var(--muted);
  margin: -0.5rem 0 0.75rem;
}

@media (max-width: 900px) {
  .pi-row {
    grid-template-columns: 1fr 1fr;
  }
  .pi-row .pi-actions,
  .pi-row-team,
  .pi-lmo {
    grid-column: 1 / -1;
  }
}

.pi-row label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.pi-row input,
.pi-row select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.pi-empty {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.5rem 0;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 1rem 0 0;
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

.memo-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.memo-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.memo-count {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.9rem;
}

.memo-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.memo-form textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

.memo-author-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.memo-author-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  min-width: 3rem;
}

.memo-author-field input {
  flex: 1;
  min-width: 8rem;
  max-width: 16rem;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.memo-form-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.memo-attach-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.attach-btn {
  margin: 0;
}

.attach-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.attach-pending {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.attach-pending.hidden {
  display: none;
}

.attach-pending li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
  background: #f5f9fc;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.attach-pending .attach-size {
  color: var(--muted);
  font-size: 0.72rem;
}

.attach-pending button {
  font-family: inherit;
  font-size: 0.72rem;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
}

.memo-attachments {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.memo-file-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
  padding: 0.35rem 0.55rem;
  background: #eef6f6;
  border-radius: 6px;
  width: fit-content;
  max-width: 100%;
  word-break: break-all;
}

.memo-file-link:hover {
  text-decoration: underline;
}

.char-count {
  font-size: 0.8rem;
  color: var(--muted);
}

.photo-btn {
  width: fit-content;
}

.photo-name {
  font-size: 0.8rem;
  color: var(--muted);
}

.memo-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: #fafcfe;
}

.memo-item time {
  font-size: 0.75rem;
  color: var(--muted);
}

.memo-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
}

.memo-author {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.memo-author::after {
  content: "·";
  margin-left: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.memo-item p {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
}

.memo-item img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  margin-top: 0.5rem;
}

.memo-item .memo-actions {
  margin-top: 0.5rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem;
}

.modal {
  border: none;
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 360px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.modal h3 {
  margin: 0 0 0.5rem;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.modal input {
  width: 100%;
  font-family: inherit;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.875rem;
  z-index: 100;
  animation: fade 0.2s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}
