/* ============ Apple Style Reset & Variables ============ */
:root {
  /* Colors - Dark Mode */
  --bg-primary: #000000;
  --bg-secondary: #1C1C1E;
  --bg-tertiary: #2C2C2E;
  --bg-elevated: #3A3A3C;

  --text-primary: #FFFFFF;
  --text-secondary: rgba(235, 235, 245, 0.6);
  --text-tertiary: rgba(235, 235, 245, 0.3);

  --accent-color: #0A84FF;
  /* iOS Blue */
  --accent-highlight: rgba(10, 132, 255, 0.15);
  --danger-color: #FF453A;
  --success-color: #30D158;
  --warning-color: #FF9F0A;

  --separator: rgba(84, 84, 88, 0.65);

  /* Dimensions & Spacing */
  --safe-area-top: env(safe-area-inset-top, 20px);
  --safe-area-bottom: env(safe-area-inset-bottom, 20px);
  --header-height: 44px;
  /* Standard iOS nav bar height */
  --radius-l: 18px;
  --radius-m: 12px;
  --radius-s: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ============ Typography ============ */
h1 {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.37px;
  line-height: 41px;
}

/* Large Title */
h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.35px;
  line-height: 28px;
}

/* Title 2 */
h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.41px;
  line-height: 22px;
}

/* Headline */
p {
  font-size: 17px;
  font-weight: 400;
  letter-spacing: -0.41px;
  line-height: 22px;
}

/* Body */
small {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: -0.08px;
  line-height: 18px;
  color: var(--text-secondary);
}

/* Caption */

/* ============ Layout Components ============ */

/* App Header (iOS Navigation Bar style) */
.app-header {
  height: calc(var(--header-height) + var(--safe-area-top));
  padding-top: var(--safe-area-top);
  background: rgba(28, 28, 30, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  position: absolute;
  top: 0;
  width: 100%;
  z-index: 100;
  transition: all 0.3s ease;
}

.header-left {
  flex: 1;
  display: flex;
  align-items: center;
}

.header-center {
  flex: 2;
  display: flex;
  justify-content: center;
  font-weight: 600;
  font-size: 17px;
}

.header-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.header-btn {
  background: none;
  border: none;
  color: var(--accent-color);
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-btn:active {
  opacity: 0.5;
}

.header-icon-btn {
  color: var(--accent-color);
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-icon-btn:active {
  background: var(--bg-tertiary);
}

/* Main Content Area */
.main-content {
  flex: 1;
  margin-top: calc(var(--header-height) + var(--safe-area-top));
  overflow-y: auto;
  padding-bottom: calc(20px + var(--safe-area-bottom));
  -webkit-overflow-scrolling: touch;
}

/* Large Page Title (Below Header) */
.page-header-large {
  padding: 16px 16px 8px 16px;
}

/* ============ Cards & Lists ============ */
.grid-layout {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px;
}

.list-layout {
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  gap: 12px;
}

/* Group Card */
.ios-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-l);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  transition: transform 0.2s;
  overflow: hidden;
}

.ios-card:active {
  transform: scale(0.96);
  background: var(--bg-tertiary);
}

.card-icon {
  width: 40px;
  height: 40px;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-color);
  margin-bottom: 4px;
}

.card-title {
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Camera Card (Thumbnail based) */
.camera-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-m);
  overflow: hidden;
}

.camera-card:active {
  opacity: 0.8;
}

.camera-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-tertiary);
  width: 100%;
  position: relative;
}

.camera-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-info {
  padding: 10px 12px;
}

.camera-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  display: inline-block;
  margin-right: 6px;
}

.camera-status-dot.online {
  background: var(--success-color);
  box-shadow: 0 0 6px rgba(48, 209, 88, 0.4);
}

/* Recording List Item */
.rec-item {
  display: flex;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: var(--radius-m);
  gap: 12px;
}

.rec-item:active {
  background: var(--bg-tertiary);
}

.rec-thumb {
  width: 100px;
  aspect-ratio: 16/9;
  background: var(--bg-tertiary);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.rec-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.rec-duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 4px;
}

.rec-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.rec-date {
  font-weight: 500;
  font-size: 15px;
}

.rec-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ============ Player Controls ============ */
.player-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.player-nav {
  position: absolute;
  top: var(--safe-area-top);
  left: 0;
  width: 100%;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
  /* background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent); */
}

.player-close-btn {
  width: 32px;
  height: 32px;
  background: rgba(44, 44, 46, 0.8);
  border-radius: 50%;
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.video-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
}

.video-wrap video {
  width: 100%;
  max-height: 100%;
}

/* Custom Controls Bar (Bottom) */
.player-controls {
  padding: 20px 30px calc(20px + var(--safe-area-bottom));
  background: rgba(28, 28, 30, 0.9);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-btn {
  background: none;
  border: none;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.control-btn svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  margin-bottom: 4px;
}

.control-btn:active {
  opacity: 0.6;
}

/* Date Selector (Horizontal Scroll) */
.date-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.date-chip {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  white-space: nowrap;
  border: none;
}

.date-chip.active {
  background: white;
  /* iOS style active state often invert */
  color: black;
  font-weight: 600;
}

/* ============ States ============ */
.hidden {
  display: none !important;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* ============ Main Layout Fixes ============ */
#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============ Custom Player Rotation Logic ============ */
/* ============ Custom Player Rotation Logic ============ */
.player-overlay.fullscreen-landscape {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  width: 100vh !important;
  height: 100vw !important;
  transform: translate(-50%, -50%) rotate(90deg) !important;
  transform-origin: center center !important;
  margin: 0 !important;
  padding: 0 !important;
  z-index: 99999 !important;
  background: #000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.player-overlay.fullscreen-landscape .video-wrap {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-overlay.fullscreen-landscape .video-wrap video {
  width: 100%;
  height: 100%;
  max-width: 100vh;
  max-height: 100vw;
  object-fit: contain !important;
}

.player-overlay.fullscreen-landscape .player-nav {
  display: none;
}

/* Adjust controls for Landscape */
.player-overlay.fullscreen-landscape .player-controls {
  position: absolute;
  bottom: 20px;
  /* Safe distance */
  left: 0;
  width: 100%;
  padding: 10px 60px;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  border-radius: 20px;
  /* Floating pill style */
  width: 80%;
  left: 10%;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
  transform: translateY(0);
}

.player-overlay.fullscreen-landscape .player-controls.controls-hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}