:root {
  color-scheme: light;
  --navy: #10243f;
  --navy-soft: #33465f;
  --blue: #1768ac;
  --blue-dark: #0d548e;
  --green: #16a36a;
  --green-dark: #0d7d50;
  --green-pale: #e9f8f0;
  --red: #dd3e45;
  --red-pale: #fff0f0;
  --amber: #dd8b13;
  --amber-pale: #fff7e8;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --page: #edf4f1;
  --border: #dce6e2;
  --text: #142033;
  --muted: #657489;
  --shadow: 0 14px 40px rgba(24, 56, 47, 0.11);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -5%, rgba(42, 172, 119, 0.16), transparent 32rem),
    linear-gradient(180deg, #f7faf9 0, var(--page) 100%);
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100dvh;
  padding: calc(28px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  place-items: center;
}

.login-card {
  width: min(100%, 430px);
  padding: 34px 24px 24px;
  overflow: hidden;
  text-align: center;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(208, 223, 217, 0.92);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 76px;
  height: 76px;
  margin: 0 auto 20px;
  background: #ecf7f3;
  border-radius: 22px;
  place-items: center;
}

.brand-mark img {
  width: 58px;
  height: 58px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(24px, 7vw, 30px);
  letter-spacing: -0.045em;
}

.login-copy {
  margin: 12px auto 26px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.login-form {
  text-align: left;
}

.login-form label {
  display: block;
  margin: 15px 2px 7px;
  color: var(--navy-soft);
  font-size: 13px;
  font-weight: 700;
}

.login-form input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  color: var(--text);
  background: #fbfdfc;
  border: 1px solid #cbd9d4;
  border-radius: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 163, 106, 0.12);
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 64px;
}

.text-button {
  position: absolute;
  top: 4px;
  right: 4px;
  height: 44px;
  padding: 0 12px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  background: transparent;
  border: 0;
}

.form-error {
  min-height: 20px;
  margin: 10px 2px 0;
  color: var(--red);
  font-size: 12px;
  line-height: 1.5;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 0 18px;
  font-weight: 800;
  border-radius: 13px;
  cursor: pointer;
}

.primary-button {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  border: 0;
  box-shadow: 0 8px 18px rgba(23, 104, 172, 0.2);
}

.primary-button:disabled,
.secondary-button:disabled,
.control-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary-button {
  color: var(--navy);
  background: #fff;
  border: 1px solid #cbd8e0;
}

.login-button {
  width: 100%;
  margin-top: 2px;
}

.login-help {
  margin: 20px 0;
  color: #7d8a9a;
  font-size: 12px;
  line-height: 1.55;
}

.company-logo {
  width: 118px;
  height: auto;
  opacity: 0.7;
}

.dashboard-view {
  width: min(100%, 680px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(22px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px 12px;
}

.header-brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.header-brand img {
  width: 43px;
  height: 43px;
  flex: none;
}

.header-brand p,
.header-brand h1 {
  margin: 0;
}

.header-brand p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.header-brand h1 {
  margin-top: 2px;
  font-size: 22px;
  letter-spacing: -0.04em;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  color: #fff;
  font-weight: 800;
  background: var(--navy);
  border: 0;
  border-radius: 50%;
  place-items: center;
}

.server-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 7px 9px 7px 14px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: 0 5px 18px rgba(27, 58, 50, 0.05);
}

.status-label {
  display: flex;
  align-items: center;
  min-width: 0;
  color: var(--navy-soft);
  font-size: 13px;
  font-weight: 750;
  gap: 7px;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: none;
  background: var(--amber);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(221, 139, 19, 0.13);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 163, 106, 0.13);
}

.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(221, 62, 69, 0.12);
}

.refresh-button {
  min-height: 36px;
  padding: 0 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  background: transparent;
  border: 0;
}

.refresh-button.loading span {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.site-section,
.count-section,
.control-section {
  margin-top: 12px;
  padding: 17px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 7px 24px rgba(27, 58, 50, 0.055);
}

.section-heading,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2,
.section-title-row h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.035em;
}

.connection-badge,
.tiny-badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 0 9px;
  flex: none;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 800;
  background: var(--green-pale);
  border-radius: 999px;
}

.connection-badge.offline,
.tiny-badge.offline {
  color: #bd353d;
  background: var(--red-pale);
}

.connection-badge.waiting,
.tiny-badge.waiting {
  color: #a5680f;
  background: var(--amber-pale);
}

.site-chips {
  display: flex;
  margin: 15px -17px 0;
  padding: 0 17px 5px;
  overflow-x: auto;
  gap: 8px;
  scrollbar-width: none;
}

.site-chips::-webkit-scrollbar {
  display: none;
}

.site-chip {
  min-height: 42px;
  padding: 0 15px;
  flex: none;
  color: var(--navy-soft);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 13px;
}

.site-chip[aria-selected="true"] {
  color: #fff;
  background: var(--navy);
  border-color: var(--navy);
  box-shadow: 0 7px 16px rgba(16, 36, 63, 0.18);
}

.site-meta {
  min-height: 18px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.count-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 14px;
  gap: 7px;
}

.count-grid article {
  min-width: 0;
  padding: 11px 5px;
  text-align: center;
  background: #f6faf8;
  border: 1px solid #e1eae6;
  border-radius: 14px;
}

.count-grid span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.count-grid strong {
  display: inline-block;
  margin-top: 5px;
  color: var(--navy);
  font-size: 22px;
  letter-spacing: -0.04em;
}

.count-grid small {
  margin-left: 2px;
  color: var(--muted);
  font-size: 9px;
}

.last-updated {
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
  gap: 9px;
}

.channel-card {
  position: relative;
  min-width: 0;
  padding: 13px 11px 11px;
  overflow: hidden;
  background: #fbfdfc;
  border: 1px solid #dae5e0;
  border-radius: 15px;
}

.channel-card.is-on {
  background: var(--green-pale);
  border-color: #a5dfc4;
}

.channel-card.is-offline {
  background: #f7f8f9;
  opacity: 0.77;
}

.channel-card.is-disabled {
  background: #f5f7f8;
  border-color: #e3e8eb;
  opacity: 0.66;
}

.channel-title-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  min-height: 35px;
  align-items: start;
  gap: 6px;
}

.channel-card h3 {
  min-height: 35px;
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.35;
  letter-spacing: -0.03em;
}

.channel-timer-line {
  display: grid;
  grid-template-columns: 7px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 34px;
  margin: 3px 0 8px;
  gap: 5px;
}

.channel-timer-text {
  overflow: hidden;
  color: #5e7186;
  font-size: 9px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
}

.channel-card.is-disabled .channel-timer-text {
  color: #9aa7b4;
}

.channel-state-dot {
  width: 8px;
  height: 8px;
  background: #aeb9c6;
  border-radius: 50%;
}

.channel-card.is-on .channel-state-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 106, 0.12);
}

.channel-timer-dot {
  width: 7px;
  height: 7px;
  background: #aeb9c6;
  border-radius: 50%;
}

.channel-timer-line.has-timer .channel-timer-dot {
  background: var(--green);
}

.channel-timer-button {
  min-height: 30px;
  padding: 0 7px;
  color: var(--navy-soft);
  font-size: 10px;
  font-weight: 800;
  background: #fff;
  border: 1px solid #c9d8d2;
  border-radius: 8px;
}

.channel-timer-button:disabled {
  color: #9ba8b2;
  background: #f1f3f4;
}

.channel-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

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

.control-button {
  min-width: 0;
  min-height: 41px;
  padding: 4px;
  overflow: hidden;
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #fff;
  border: 1px solid #cad8d2;
  border-radius: 10px;
}

.control-button.on {
  color: var(--green-dark);
  border-color: #92d3b4;
}

.control-button.off {
  color: #bd353d;
  border-color: #ecc3c5;
}

.control-button.pulse {
  color: var(--blue);
  border-color: #b6d1e6;
}

.empty-state {
  margin-top: 14px;
  padding: 28px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed #cddbd5;
  border-radius: 14px;
}

.app-footer {
  display: flex;
  align-items: center;
  padding: 20px 8px 4px;
  color: #788797;
  font-size: 10px;
  line-height: 1.5;
  gap: 10px;
}

.app-footer img {
  width: 84px;
  height: auto;
  flex: none;
  opacity: 0.55;
}

.account-menu,
.sheet-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  background: rgba(12, 26, 43, 0.42);
  backdrop-filter: blur(6px);
}

.account-menu {
  display: grid;
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  place-items: start center;
}

.account-menu-card {
  position: relative;
  width: min(100%, 430px);
  margin-top: 70px;
  padding: 24px;
  background: #fff;
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.account-menu-card strong,
.account-menu-card span {
  display: block;
}

.account-menu-card strong {
  font-size: 20px;
}

.account-menu-card span {
  margin: 6px 0 20px;
  color: var(--muted);
  font-size: 13px;
}

.account-menu-card .secondary-button {
  width: 100%;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #667486;
  font-size: 27px;
  line-height: 1;
  background: transparent;
  border: 0;
  border-radius: 50%;
  place-items: center;
}

.sheet-backdrop {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.confirm-sheet {
  position: relative;
  width: min(100%, 680px);
  padding: 14px 22px calc(22px + var(--safe-bottom));
  text-align: center;
  background: #fff;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -16px 45px rgba(12, 26, 43, 0.15);
  animation: sheet-up 0.22s ease-out;
}

.timer-sheet {
  position: relative;
  width: min(100%, 680px);
  max-height: min(92dvh, 760px);
  padding: 14px 20px calc(20px + var(--safe-bottom));
  overflow-y: auto;
  background: #fff;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -16px 45px rgba(12, 26, 43, 0.15);
  animation: sheet-up 0.22s ease-out;
}

.timer-sheet h2 {
  margin: 0;
  font-size: 23px;
  letter-spacing: -0.04em;
}

.timer-site-name {
  margin: 5px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.field-label,
.timer-fields legend {
  display: block;
  margin: 0 0 7px;
  color: var(--navy-soft);
  font-size: 12px;
  font-weight: 800;
}

.timer-channel-name {
  min-height: 46px;
  padding: 13px 12px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 850;
  background: #f3f8fb;
  border: 1px solid #d2e2ed;
  border-radius: 12px;
}

.timer-enable-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 65px;
  margin: 12px 0;
  padding: 10px 12px;
  background: #f6faf8;
  border: 1px solid #e0eae6;
  border-radius: 13px;
  gap: 12px;
}

.timer-enable-row strong,
.timer-enable-row span {
  display: block;
}

.timer-enable-row strong {
  font-size: 13px;
}

.timer-enable-row > div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.switch {
  position: relative;
  width: 50px;
  height: 30px;
  flex: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch > span {
  position: absolute;
  background: #b8c4ce;
  border-radius: 999px;
  cursor: pointer;
  inset: 0;
  transition: background 0.2s;
}

.switch > span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  content: '';
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(15, 34, 55, 0.2);
  transition: transform 0.2s;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.switch input:disabled + span {
  cursor: not-allowed;
  opacity: 0.55;
}

.timer-fields {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.timer-fields:disabled {
  opacity: 0.5;
}

.mode-segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: #eef3f5;
  border-radius: 12px;
  gap: 3px;
}

.mode-segment label {
  min-width: 0;
}

.mode-segment input {
  position: absolute;
  opacity: 0;
}

.mode-segment span {
  display: grid;
  min-height: 40px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  border-radius: 9px;
  place-items: center;
}

.mode-segment input:checked + span {
  color: var(--blue);
  background: #fff;
  box-shadow: 0 3px 9px rgba(22, 55, 78, 0.1);
}

.timer-mode-help {
  min-height: 31px;
  margin: 8px 2px 10px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.time-grid label span {
  display: block;
  margin: 0 2px 5px;
  color: var(--navy-soft);
  font-size: 10px;
  font-weight: 750;
}

.time-grid input {
  width: 100%;
  height: 46px;
  padding: 0 9px;
  color: var(--text);
  background: #fbfdfc;
  border: 1px solid #cbd9d4;
  border-radius: 11px;
}

.timer-actions {
  margin-top: 16px;
}

@keyframes sheet-up {
  from { transform: translateY(30px); opacity: 0; }
}

.sheet-handle {
  width: 42px;
  height: 5px;
  margin: 0 auto 14px;
  background: #d6dfe4;
  border-radius: 999px;
}

.confirm-icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 4px auto 13px;
  color: var(--blue);
  font-size: 24px;
  font-weight: 900;
  background: #eaf3fa;
  border-radius: 17px;
  place-items: center;
}

.confirm-sheet h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.04em;
}

.confirm-sheet > p:not(.section-kicker) {
  margin: 10px auto 21px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 9px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 16px;
  bottom: calc(18px + var(--safe-bottom));
  left: 16px;
  max-width: 500px;
  min-height: 52px;
  margin: auto;
  padding: 15px 18px;
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.5;
  text-align: center;
  background: #15304d;
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(9, 25, 43, 0.28);
  animation: toast-in 0.2s ease-out;
}

.toast.error {
  background: #b6323a;
}

@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
}

@media (max-width: 359px) {
  .dashboard-view { padding-right: 10px; padding-left: 10px; }
  .site-section, .count-section, .control-section { padding: 14px; }
  .site-chips { margin-right: -14px; margin-left: -14px; padding-right: 14px; padding-left: 14px; }
  .channel-grid { gap: 7px; }
  .channel-card { padding-right: 9px; padding-left: 9px; }
  .count-grid strong { font-size: 19px; }
}

@media (min-width: 681px) {
  .dashboard-view { padding-top: calc(22px + var(--safe-top)); }
  .site-section, .count-section, .control-section { padding: 21px; }
  .site-chips { margin-right: -21px; margin-left: -21px; padding-right: 21px; padding-left: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
