:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: #202420;
  background: #f4f6f3;
  --surface: #ffffff;
  --surface-muted: #f4f6f3;
  --surface-hover: #eef2ed;
  --text: #202420;
  --muted: #666d67;
  --border: #d5dbd5;
  --border-strong: #b9c2ba;
  --accent: #176b45;
  --accent-hover: #0f5736;
  --accent-soft: #e4f2ea;
  --blue: #236a91;
  --warning: #9a6100;
  --warning-soft: #fff1ce;
  --danger: #b62f2f;
  --danger-hover: #922222;
  --danger-soft: #fbe7e7;
  --shadow: 0 12px 32px rgba(31, 42, 34, 0.16);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body,
#app-root {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 280px;
  background: var(--surface-muted);
}

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

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

button,
input,
select,
textarea,
a {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.boot-view,
.login-view {
  width: 100%;
  height: 100%;
}

.boot-view {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.boot-view p {
  margin: 0;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.login-view {
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 20px;
  background: #eef1ec;
}

.login-panel {
  width: min(100%, 390px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--border);
}

.login-header h1,
.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.login-header p,
.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff !important;
  font-weight: 800;
  font-size: 15px !important;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  font-size: 12px !important;
}

.login-form {
  display: grid;
  gap: 8px;
  padding: 22px 24px 26px;
}

.login-form > label,
.form-grid label > span,
.filterbar label > span {
  color: #4e554f;
  font-size: 13px;
  font-weight: 650;
}

.login-form input,
.form-grid input,
.form-grid select,
.form-grid textarea,
.filterbar input,
.filterbar select,
.playlist-bar select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible,
.table-scroll:focus-visible {
  outline: 3px solid rgba(35, 106, 145, 0.28);
  outline-offset: 1px;
  border-color: var(--blue);
}

.captcha-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 126px;
  gap: 8px;
}

.captcha-button {
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface-muted);
  overflow: hidden;
}

.captcha-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

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

.button.primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.button.secondary {
  border-color: var(--border-strong);
  background: var(--surface);
}

.button.secondary:hover,
.button.ghost:hover {
  background: var(--surface-hover);
}

.button.ghost {
  border-color: transparent;
  color: #4e554f;
}

.button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.button.danger:hover {
  border-color: var(--danger-hover);
  background: var(--danger-hover);
}

.button.wide {
  width: 100%;
  margin-top: 8px;
}

.button.square {
  width: 40px;
  min-width: 40px;
  padding: 0;
}

.form-error {
  margin: 6px 0 0;
  padding: 9px 11px;
  border-left: 3px solid var(--danger);
  background: var(--danger-soft);
  color: #832323;
  font-size: 13px;
}

.admin-view {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--surface-muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-width: 0;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand-line,
.topbar-actions {
  display: flex;
  align-items: center;
}

.brand-line {
  min-width: 0;
  gap: 10px;
}

.topbar-actions {
  gap: 8px;
}

.playlist-bar {
  display: grid;
  grid-template-columns: auto 90px minmax(0, 1fr) auto auto;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.playlist-bar > label {
  align-self: center;
  color: #4e554f;
  font-size: 13px;
  font-weight: 650;
}

.playlist-url {
  min-width: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #f8faf7;
}

.playlist-url code,
.url-text {
  display: block;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-all;
  color: #2c4939;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  user-select: text;
}

.filterbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 200px 170px;
  align-items: end;
  gap: 10px;
  min-width: 0;
  padding: 9px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8faf7;
}

.filterbar label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.filterbar input,
.filterbar select,
.playlist-bar select {
  min-height: 36px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.channel-region {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  padding: 12px 20px;
}

.table-scroll {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  scrollbar-color: #aab4ac #eef1ed;
  scrollbar-width: auto;
}

.channel-table {
  width: 1584px;
  min-width: 1584px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
}

.channel-table .col-number { width: 56px; }
.channel-table .col-name { width: 180px; }
.channel-table .col-source { width: 360px; }
.channel-table .col-output { width: 360px; }
.channel-table .col-status { width: 210px; }
.channel-table .col-parser { width: 120px; }
.channel-table .col-category { width: 130px; }
.channel-table .col-proxy { width: 90px; }
.channel-table .col-actions { width: 78px; }

.channel-table th,
.channel-table td {
  padding: 10px 11px;
  border-bottom: 1px solid #e1e5e1;
  border-right: 1px solid #edf0ed;
  text-align: left;
  vertical-align: top;
}

.channel-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 44px;
  background: #edf1ec;
  color: #424942;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.channel-table td {
  background: var(--surface);
  color: #2c312d;
  font-size: 13px;
}

.channel-table tbody tr:hover td {
  background: #f7faf7;
}

.channel-table tbody tr:last-child td {
  border-bottom: 0;
}

.channel-table th:last-child,
.channel-table td:last-child {
  border-right: 0;
}

.channel-table .actions-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  box-shadow: -6px 0 10px rgba(36, 45, 38, 0.06);
}

.channel-table th.actions-cell {
  z-index: 5;
  background: #e6ebe5;
}

.channel-table tbody tr:hover .actions-cell {
  background: #f0f5f0;
}

.channel-name {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  font-weight: 680;
}

.child-prefix {
  color: var(--muted);
  flex: 0 0 auto;
}

.status-block {
  display: grid;
  gap: 4px;
}

.status-label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ecefec;
  color: #4f5650;
  font-size: 12px;
  font-weight: 700;
}

.status-label.live {
  background: var(--accent-soft);
  color: #135c3b;
}

.status-label.warning {
  background: var(--warning-soft);
  color: #805000;
}

.status-label.error,
.status-label.expired {
  background: var(--danger-soft);
  color: #8c2929;
}

.status-message,
.cell-secondary {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.status-time {
  color: #838a84;
  font-size: 11px;
}

.proxy-stack {
  display: grid;
  gap: 3px;
  color: #4d554e;
  font-size: 12px;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-action {
  width: 52px;
  min-height: 34px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: #394039;
  font-size: 12px;
  font-weight: 650;
}

.row-action:hover {
  background: var(--surface-hover);
}

.table-empty {
  position: sticky;
  left: 0;
  width: min(100%, 620px);
  padding: 48px 20px;
  color: var(--muted);
  text-align: center;
}

.table-loading {
  position: sticky;
  left: calc(50% - 60px);
  bottom: 16px;
  z-index: 6;
  width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 4px 14px rgba(31, 42, 34, 0.12);
  color: var(--muted);
  font-size: 12px;
}

.table-loading .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.dialog {
  width: min(720px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(31, 38, 32, 0.46);
}

.dialog-layout {
  max-height: inherit;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  margin: 0;
  overflow: hidden;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2,
.confirm-dialog h2 {
  margin: 2px 0 0;
  font-size: 18px;
}

.dialog-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.dialog-body {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #f8faf7;
}

.dialog-footer .dialog-delete {
  margin-right: auto;
}

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

.form-grid label {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 5px;
}

.form-grid .full-field,
.form-grid .toggle-field,
.panel-actions {
  grid-column: 1 / -1;
}

.form-grid textarea {
  min-height: 80px;
  overflow-y: hidden;
}

.form-grid input:read-only,
.form-grid textarea:read-only {
  background: #f3f5f2;
}

.toggle-field {
  display: flex !important;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px !important;
  min-height: 40px;
}

.toggle-field input {
  width: 20px;
  min-height: 20px;
  margin: 0;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.settings-dialog {
  width: min(660px, calc(100vw - 24px));
}

.settings-dialog .dialog-layout {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.settings-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 18px 0;
  border-bottom: 1px solid var(--border);
}

.tab-button {
  min-height: 38px;
  padding: 7px 12px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.tab-button.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.about-panel p {
  margin-top: 0;
  font-size: 16px;
  font-weight: 700;
}

.about-panel dl {
  margin: 0 0 20px;
}

.about-panel dl div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.about-panel dt {
  color: var(--muted);
}

.about-panel dd {
  margin: 0;
}

.confirm-dialog {
  width: min(430px, calc(100vw - 24px));
}

.confirm-layout {
  margin: 0;
}

.confirm-layout h2,
.confirm-layout > p {
  padding-right: 18px;
  padding-left: 18px;
}

.confirm-layout h2 {
  padding-top: 18px;
}

.confirm-layout > p {
  margin: 10px 0 20px;
  color: #535a54;
  overflow-wrap: anywhere;
}

.toast-region {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 1000;
  width: min(360px, calc(100vw - 24px));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  border-radius: 5px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(31, 42, 34, 0.16);
  color: #303630;
  font-size: 13px;
}

.toast.error {
  border-left-color: var(--danger);
}

@media (max-width: 760px) {
  .topbar {
    padding: 8px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-actions .button {
    min-height: 44px;
    padding: 7px 9px;
    font-size: 12px;
  }

  .brand-line {
    gap: 7px;
  }

  .topbar h1 {
    font-size: 17px;
  }

  .topbar p {
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .playlist-bar {
    grid-template-columns: 82px minmax(0, 1fr) auto;
    gap: 6px;
    padding: 8px;
  }

  .playlist-bar > label {
    grid-column: 1 / -1;
  }

  .playlist-bar select {
    width: 82px;
  }

  .playlist-url {
    min-height: 44px;
  }

  .playlist-bar .button {
    min-height: 44px;
    padding-right: 10px;
    padding-left: 10px;
  }

  #new-channel {
    grid-column: 1 / -1;
    width: 100%;
  }

  .filterbar {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 7px;
    padding: 8px;
  }

  .filterbar .search-field {
    grid-column: 1 / -1;
  }

  .filterbar input,
  .filterbar select {
    min-height: 40px;
  }

  .channel-region {
    padding: 8px;
  }

  .table-scroll {
    border-radius: 4px;
  }

  .channel-table th,
  .channel-table td {
    padding: 9px 8px;
  }

  .row-action {
    min-height: 44px;
  }

  .dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .dialog-header {
    padding: 13px 14px;
  }

  .dialog-body {
    padding: 14px;
  }

  .dialog-footer {
    padding: 10px 14px;
  }

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

  .settings-tabs {
    padding-right: 8px;
    padding-left: 8px;
    overflow-x: auto;
  }

  .settings-tabs .tab-button {
    min-height: 44px;
  }

  .input-action {
    grid-template-columns: minmax(0, 1fr);
  }

  .input-action .button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .topbar-actions #refresh-button {
    display: none;
  }

  .topbar-actions .button {
    padding-right: 8px;
    padding-left: 8px;
  }

  .playlist-url code {
    font-size: 11px;
  }

}

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