:root {
  color-scheme: light;
  --bg: #f2f5f6;
  --surface: #ffffff;
  --text: #242424;
  --muted: #5e686d;
  --line: #d4dade;
  --primary: #217a55;
  --primary-dark: #15573c;
  --danger: #b23b35;
  --warning: #8a650d;
  --shadow: 0 14px 36px rgba(36, 36, 36, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Segoe UI",
    "Malgun Gothic",
    system-ui,
    sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
  font-weight: 750;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

h3 {
  font-size: 14px;
  line-height: 1.2;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.status-strip,
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f7f5;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.pill.good {
  border-color: rgba(33, 122, 85, 0.35);
  background: rgba(33, 122, 85, 0.1);
  color: var(--primary-dark);
}

.pill.bad {
  border-color: rgba(178, 59, 53, 0.35);
  background: rgba(178, 59, 53, 0.1);
  color: var(--danger);
}

.pill.warn {
  border-color: rgba(138, 101, 13, 0.35);
  background: rgba(138, 101, 13, 0.12);
  color: var(--warning);
}

.workspace {
  display: grid;
  gap: 18px;
  padding: 20px clamp(16px, 3vw, 36px);
}

.camera-section {
  min-width: 0;
}

.camera-tabs {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 10px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8edef;
}

.camera-tab {
  min-height: 32px;
  padding: 5px 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.camera-tab:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}

.camera-tab.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 1px 4px rgba(36, 36, 36, 0.12);
}

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

.camera-view {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #bfc8cc;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(36, 36, 36, 0.07);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.camera-view.selected {
  border-color: rgba(33, 122, 85, 0.75);
  box-shadow: 0 0 0 2px rgba(33, 122, 85, 0.14), var(--shadow);
}

.camera-view.motion-active {
  border-color: rgba(178, 59, 53, 0.72);
}

.camera-view-heading {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.camera-card-status {
  display: flex;
  gap: 6px;
}

.camera-card-status span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #edf0f1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.camera-card-status .good {
  background: rgba(33, 122, 85, 0.12);
  color: var(--primary-dark);
}

.camera-card-status .bad {
  background: rgba(178, 59, 53, 0.12);
  color: var(--danger);
}

.camera-view > img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #222;
}

.ptz-toolbar {
  min-height: 82px;
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #303538;
  background: #202527;
  color: #f5f7f7;
}

.ptz-direction {
  display: grid;
  grid-template-columns: repeat(3, 32px);
  grid-template-rows: repeat(3, 26px);
  gap: 2px;
}

.ptz-direction .icon-button {
  width: 32px;
  height: 26px;
  min-height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #4b5559;
  border-radius: 5px;
  background: #343c3f;
  color: #fff;
  font-size: 17px;
  line-height: 1;
}

.ptz-direction .icon-button:hover {
  background: #465155;
}

.ptz-up { grid-column: 2; grid-row: 1; }
.ptz-left { grid-column: 1; grid-row: 2; }
.ptz-home { grid-column: 2; grid-row: 2; }
.ptz-right { grid-column: 3; grid-row: 2; }
.ptz-down { grid-column: 2; grid-row: 3; }

.zoom-control {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) 40px;
  gap: 8px;
  align-items: center;
  color: #dce2e4;
  font-size: 12px;
  font-weight: 700;
}

.zoom-control input {
  min-width: 80px;
  accent-color: #43a77b;
}

.zoom-control output {
  color: #fff;
  text-align: right;
}

.preset-control {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto auto;
  gap: 5px;
}

.preset-control select {
  min-width: 98px;
  height: 32px;
  border: 1px solid #556064;
  border-radius: 6px;
  background: #2d3437;
  color: #fff;
  padding: 0 7px;
  font: inherit;
  font-size: 12px;
}

.preset-control button {
  min-height: 32px;
  padding: 5px 8px;
  border-color: #596468;
  background: #343c3f;
  color: #fff;
  font-size: 12px;
}

.preset-control button:hover {
  background: #465155;
}

.ptz-position {
  grid-column: 2 / -1;
  color: #aeb9bd;
  font-size: 11px;
}

.operations-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 18px;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(36, 36, 36, 0.06);
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.event-heading-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.event-camera-filter {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #e8edef;
}

.event-camera-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.event-camera-option:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}

.event-camera-option.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(36, 36, 36, 0.14);
}

.event-camera-option.camera-one::before,
.event-camera-option.camera-two::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  content: "";
}

.event-camera-option.camera-one::before {
  background: #217a55;
}

.event-camera-option.camera-two::before {
  background: #356fb5;
}

.event-camera-count {
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(36, 36, 36, 0.08);
  color: inherit;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
}

.event-date-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.event-date-filter select {
  min-height: 34px;
  max-width: 250px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 30px 5px 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.event-date-filter select:focus {
  outline: 2px solid rgba(33, 122, 85, 0.22);
  border-color: rgba(33, 122, 85, 0.55);
}

button {
  appearance: none;
  border: 0;
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 13px;
  background: var(--primary);
  color: white;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  border: 1px solid var(--line);
  background: #eef1f2;
  color: var(--text);
}

button.secondary:hover {
  background: #dfe5e7;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

button.danger-button:hover {
  background: #8e2e2a;
}

button.danger-outline {
  border: 1px solid rgba(178, 59, 53, 0.5);
  background: #fff;
  color: var(--danger);
}

button.danger-outline:hover {
  background: rgba(178, 59, 53, 0.09);
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
  font-size: 23px;
  line-height: 1;
}

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

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-panel h1 {
  margin-bottom: 8px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

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

.login-form input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.login-form input:focus {
  outline: 2px solid rgba(33, 122, 85, 0.25);
  border-color: rgba(33, 122, 85, 0.55);
}

.metrics {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
}

.metrics div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

dt {
  color: var(--muted);
  font-size: 13px;
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 650;
}

.error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.motion-alert {
  margin-top: 12px;
  min-height: 58px;
  display: grid;
  align-items: center;
  padding: 12px;
  border-radius: 7px;
  background: #f2f5f6;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.motion-alert.active {
  background: rgba(33, 122, 85, 0.12);
  color: var(--primary-dark);
  font-weight: 700;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 18px;
  padding: 0 clamp(16px, 3vw, 36px) 30px;
}

.content-grid > *,
.operations-grid > * {
  min-width: 0;
}

.table-wrap {
  max-height: 720px;
  overflow-x: auto;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

tr.downloadable {
  cursor: pointer;
}

tr.downloadable:hover td {
  background: #f2f5f6;
}

.event-date-row th,
.event-hour-row th {
  padding: 9px 8px;
}

.event-date-row th {
  background: #e9eef0;
  color: var(--text);
  font-size: 13px;
}

.event-hour-row th {
  background: #f5f7f8;
  color: #40515a;
  font-size: 12px;
}

.event-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.event-group-heading span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.camera-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid #b8c6cc;
  border-radius: 6px;
  background: #edf2f4;
  color: #30454f;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.camera-badge::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.camera-badge-one {
  border-color: #7dbb9c;
  background: #e1f3e9;
  color: #17603d;
}

.camera-badge-two {
  border-color: #8caee0;
  background: #e7effb;
  color: #24518e;
}

.motion-alert .camera-badge {
  margin-right: 8px;
}

.event-video-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.event-video-cell span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.event-person-cell {
  color: #40515a;
  font-size: 12px;
  font-weight: 700;
}

.recordings-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.range-delete-toolbar {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.range-delete-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 9px;
  align-items: end;
}

.range-delete-fields label {
  min-width: 0;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.range-delete-fields input,
.range-delete-fields select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.range-delete-fields input:focus,
.range-delete-fields select:focus {
  outline: 2px solid rgba(33, 122, 85, 0.22);
  border-color: rgba(33, 122, 85, 0.55);
}

.range-delete-fields .all-day-control {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding-bottom: 1px;
}

.all-day-control input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--primary);
}

.range-delete-actions {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.range-delete-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.range-delete-dialog::backdrop {
  background: rgba(20, 27, 30, 0.55);
}

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.range-delete-label {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.range-delete-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 14px 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--line);
}

.range-delete-summary div {
  min-width: 0;
  padding: 10px;
  background: var(--surface);
}

.range-delete-summary dt {
  color: var(--muted);
  font-size: 12px;
}

.range-delete-summary dd {
  margin: 3px 0 0;
  font-size: 15px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.range-delete-items {
  max-height: 240px;
  margin-top: 10px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.range-delete-items > div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 2px;
  border-bottom: 1px solid #e7ebed;
  font-size: 12px;
}

.range-delete-items > div:last-child {
  border-bottom: 0;
}

.range-delete-items span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.danger-message {
  margin: 12px 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.dialog-actions {
  justify-content: flex-end;
}

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

.group-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.recording-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 3px;
}

.recording-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafb;
}

.recording-item a {
  color: var(--primary-dark);
  font-weight: 750;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.recording-meta {
  color: var(--muted);
  font-size: 12px;
}

.recording-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border: 1px solid rgba(33, 122, 85, 0.28);
  border-radius: 6px;
  background: rgba(33, 122, 85, 0.08);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.download-link:hover {
  background: rgba(33, 122, 85, 0.16);
}

.playback-page {
  min-height: 100vh;
}

.playback-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 36px);
}

.playback-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.playback-header h1 {
  font-size: clamp(18px, 2.6vw, 28px);
  overflow-wrap: anywhere;
}

.playback-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.playback-stage {
  min-width: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  overflow: hidden;
}

.playback-video {
  display: block;
  width: 100%;
  max-height: calc(100vh - 128px);
  background: #111;
}

.playback-audio {
  width: min(720px, calc(100vw - 48px));
}

.playback-sequence-controls {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 12px;
  background: #1d1d1d;
  color: #fff;
}

.playback-sequence-controls button {
  width: 36px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
}

.playback-nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 82px;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  background: #2b624a;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.playback-nav-button:hover {
  background: #35775a;
}

.playback-nav-button.disabled {
  background: #2b2b2b;
  color: #777;
  cursor: default;
}

.playback-sequence-status {
  min-width: 82px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.kind-badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.kind-badge.merged {
  background: rgba(33, 122, 85, 0.12);
  color: var(--primary-dark);
}

.kind-badge.clip {
  background: rgba(138, 101, 13, 0.12);
  color: var(--warning);
}

.kind-badge.audio {
  background: rgba(72, 88, 135, 0.12);
  color: #34426d;
}

.kind-badge.video {
  background: rgba(36, 36, 36, 0.08);
  color: var(--muted);
}

.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 14px 0;
  text-align: center;
}

@media (max-width: 980px) {
  .camera-grid,
  .operations-grid,
  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 700px) {
  .ptz-toolbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .preset-control {
    grid-column: 1 / -1;
  }

  .ptz-position {
    grid-column: 1 / -1;
  }

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

@media (max-width: 560px) {
  .panel-heading {
    align-items: flex-start;
  }

  .event-heading-tools {
    width: 100%;
    align-items: flex-end;
    flex-direction: column;
    gap: 5px;
  }

  .event-camera-filter {
    max-width: 100%;
    overflow-x: auto;
  }

  .event-date-filter select {
    max-width: 190px;
  }

  .playback-header {
    flex-direction: column;
  }

  .playback-actions {
    justify-content: flex-start;
  }

  .metrics div,
  .recording-item {
    grid-template-columns: 1fr;
  }

  .recording-side {
    justify-items: start;
  }

  .range-delete-fields,
  .range-delete-summary {
    grid-template-columns: 1fr;
  }

  .range-delete-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .range-delete-items > div {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .range-delete-items strong {
    grid-column: 2;
  }

  th,
  td {
    padding: 9px 6px;
  }
}
