/* Scale Display PWA - Dedicated CSS
 * Purpose: Dark-themed tablet display for live scale weight + bag timer
 * Target: Samsung Galaxy Tab A7 (10.4", 2000x1200) in landscape mode
 * Layout: 50/50 split with circular progress rings
 */

/* ===== CSS Variables ===== */
:root {
  /* Layout */
  --header-height: 48px;
  --circle-size: min(45vh, 45vw);

  /* Dark Theme Colors */
  --bg-dark: #1a1a1a;
  --text-light: #f5f5f5;
  --text-muted: #a0a0a0;

  /* Rogue Origin Brand */
  --ro-green: #668971;
  --ro-gold: #e4aa4f;

  /* Status Colors */
  --color-success: #4caf50;
  --color-danger: #c45c4a;

  /* Ring */
  --ring-bg: rgba(255, 255, 255, 0.1);

  /* Scale Ring States */
  --scale-filling: #62758d;
  --scale-near-target: #e4aa4f;
  --scale-at-target: #4caf50;
  --scale-stale: #808080;

  /* Typography */
  --font-display: 'JetBrains Mono', monospace;
  --font-ui: 'Outfit', sans-serif;

  /* Animations */
  --transition-fast: 0.2s ease;
  --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-dark);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.5s ease;
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--ro-green);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}
.skip-link:focus { top: 0; }

/* ===== Header ===== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  height: var(--header-height);
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0;
  color: var(--ro-gold);
}

#langToggle {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-light);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
  min-width: 44px;
  min-height: 44px;
}

#langToggle:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ===== Main Grid ===== */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 0.75rem;
  overflow: hidden;
  min-height: 0;
}

/* ===== Panels ===== */
.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 1rem;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.panel h2 {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Unit toggle button */
.unit-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ro-gold);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
  min-width: 56px;
  min-height: 44px;
}

.unit-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

/* ============================================================
   SCALE PANEL (Left Side)
   ============================================================ */

/* Scale SVG Ring */
.ring {
  width: var(--circle-size);
  height: var(--circle-size);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.ring circle:first-child {
  stroke: var(--ring-bg);
}

.ring circle:last-child {
  stroke: var(--scale-filling);
  transition: stroke-dashoffset 0.15s cubic-bezier(0.4, 0, 0.2, 1),
              stroke 0.2s ease;
}

/* Scale Center Text */
.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 1;
}

.value {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1;
  margin: 0;
  color: var(--text-light);
}

#scaleWeight {
  font-size: clamp(2.5rem, 7vw, 5rem);
}

.label {
  font-size: clamp(1rem, 2vw, 1.4rem);
  color: var(--text-muted);
  margin-top: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Scale Status Dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--color-success);
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  box-shadow: 0 0 8px currentColor;
  transition: background-color var(--transition-fast);
}

.status-dot.stale {
  background-color: var(--color-danger);
  animation: pulse-red 2s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--color-danger); }
  50% { opacity: 0.5; box-shadow: 0 0 16px var(--color-danger); }
}

/* Scale Ring Color States */
#scale-panel .ring circle:last-child { stroke: var(--scale-filling); }
#scale-panel.near-target .ring circle:last-child { stroke: var(--scale-near-target); }
#scale-panel.at-target .ring circle:last-child { stroke: var(--scale-at-target); }
#scale-panel.stale .ring circle:last-child { stroke: var(--scale-stale); }


/* ============================================================
   TIMER PANEL (Right Side)
   - Classes manipulated by scoreboard/timer.js
   ============================================================ */

/* Timer container - fills parent panel */
.timer-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

/* Timer color state backgrounds */
.timer-panel.green {
  background: linear-gradient(180deg, rgba(76, 175, 80, 0.2) 0%, transparent 100%);
}
.timer-panel.yellow {
  background: linear-gradient(180deg, rgba(228, 170, 79, 0.2) 0%, transparent 100%);
}
.timer-panel.red {
  background: linear-gradient(180deg, rgba(196, 92, 74, 0.25) 0%, transparent 100%);
  animation: timer-panel-pulse-red 1s ease-in-out infinite;
}
.timer-panel.neutral {
  background: transparent;
}

@keyframes timer-panel-pulse-red {
  0%, 100% { box-shadow: inset 0 0 30px rgba(196, 92, 74, 0.15); }
  50% { box-shadow: inset 0 0 60px rgba(196, 92, 74, 0.3); }
}

/* Timer ring container */
.timer-display {
  position: relative;
  width: var(--circle-size);
  height: var(--circle-size);
}

/* Timer SVG ring */
.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--ring-bg);
  stroke-width: 10;
}

.timer-ring-progress {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}

.timer-ring-progress.green {
  stroke: #22c55e;
  filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.5));
}
.timer-ring-progress.yellow {
  stroke: #facc15;
  filter: drop-shadow(0 0 6px rgba(250, 204, 21, 0.5));
}
.timer-ring-progress.red {
  stroke: #ef4444;
  filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.7));
}

/* Timer center text (overlaid on ring) */
.timer-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-value {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 7vw, 5rem);
  font-weight: 900;
  color: #fff;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.timer-value.green {
  color: #4ade80;
  text-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
}
.timer-value.yellow {
  color: #fde047;
  text-shadow: 0 0 15px rgba(250, 204, 21, 0.4);
}
.timer-value.red {
  color: #f87171;
  text-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
  animation: urgentPulse 0.8s ease-in-out infinite;
}

@keyframes urgentPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.timer-label {
  font-family: var(--font-ui);
  font-size: clamp(0.9rem, 1.5vw, 1.2rem);
  color: rgba(255, 255, 255, 0.5);
  margin-top: 4px;
  text-transform: uppercase;
}

/* Overtime glow on ring container */
.timer-display.overtime {
  animation: overtimeGlow 0.8s ease-in-out infinite;
}
.timer-display.overtime .timer-ring-progress {
  animation: overtimePulse 0.8s ease-in-out infinite;
}

@keyframes overtimeGlow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.3)); }
  50% { filter: drop-shadow(0 0 25px rgba(239, 68, 68, 0.6)); }
}
@keyframes overtimePulse {
  0%, 100% { stroke-width: 10; }
  50% { stroke-width: 13; }
}

/* Timer target info line */
.timer-target {
  font-family: var(--font-ui);
  font-size: clamp(0.9rem, 1.5vw, 1.1rem);
  color: rgba(255, 255, 255, 0.4);
  margin-top: 0.75rem;
  text-align: center;
}

.timer-target span {
  color: var(--ro-gold);
  font-weight: 600;
}

#timerTargetTime {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-light);
}


/* ============================================================
   BODY TIMER STATE (set by timer.js)
   ============================================================ */

body.timer-green {
  background: var(--bg-dark) radial-gradient(ellipse at bottom right, rgba(76, 175, 80, 0.12) 0%, var(--bg-dark) 50%);
}
body.timer-yellow {
  background: var(--bg-dark) radial-gradient(ellipse at bottom right, rgba(228, 170, 79, 0.12) 0%, var(--bg-dark) 50%);
}
body.timer-red {
  background: var(--bg-dark) radial-gradient(ellipse at bottom right, rgba(196, 92, 74, 0.12) 0%, var(--bg-dark) 50%);
}
body.timer-neutral {
  background: var(--bg-dark);
}


/* ============================================================
   LOADING OVERLAY
   ============================================================ */

#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--ro-gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

#loading-overlay p {
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}


/* ============================================================
   RESPONSIVE — Galaxy Tab A7 Lite (8.7", 1340x800)
   ============================================================ */

@media screen and (max-height: 500px) {
  :root {
    --header-height: 36px;
    --circle-size: min(28vh, 28vw);
  }

  header h1 { font-size: 0.9rem; }
  .panel h2 { font-size: 0.75rem; top: 0.5rem; }
  main { gap: 0.5rem; padding: 0.5rem; }
  .timer-target { font-size: 0.7rem; margin-top: 0.5rem; }
}

/* ============================================================
   PORTRAIT MODE WARNING
   ============================================================ */

@media screen and (orientation: portrait) {
  body::before {
    content: "Please rotate to landscape / Gire a horizontal";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    z-index: 9999;
    font-size: 1.2rem;
    max-width: 80%;
  }
}
