﻿/*
  Styles for the Subnet Calculator UI
  - CSS variables define the theme (dark/light) and provider accent colors
  - Layout primitives (grid, rows, cards) and typographic scales
  - Bit visualizer cells, bracket bars, and subtle animations
  - Responsive tweaks and small utilities
*/
/* Minimal styles: layout + bitflip animation + polish */
:root {
  --bg: #0b1220; /* slate-950-ish */
  /* Make the gradient layers larger and fade later to avoid visible edges while scrolling */
  --bg-gradient: radial-gradient(1600px 900px at 20% 0%, rgba(14,116,144,0.14), transparent 72%), radial-gradient(1600px 900px at 80% 100%, rgba(59,130,246,0.10), transparent 78%);
  --panel: rgba(15, 23, 42, 0.55); /* slate-900/55 */
  --border: #334155; /* slate-700 */
  --text: #e2e8f0; /* slate-200 */
  --muted: #94a3b8; /* slate-400 */
  --accent: #0e7490; /* default accent (cyan-700) */
  --accent-border: #155e75; /* default accent border (cyan-600) */
  --warning: #f59e0b;
  --ring: rgba(14,116,144,0.45);
  --surface: #0b1326; /* control bg */
  --surface-alt: #0f1930;
  --cell-bg: #334155; /* bit cell */
  --cell-border: #334155;
}

/* Light theme overrides */
html[data-theme="light"] {
  --bg: #f8fafc; /* slate-50 */
  /* Larger, softer gradient in light mode as well */
  --bg-gradient: radial-gradient(1600px 900px at 20% 0%, rgba(14,116,144,0.08), transparent 72%), radial-gradient(1600px 900px at 80% 100%, rgba(2,132,199,0.06), transparent 78%);
  --panel: rgba(255,255,255,0.7);
  --border: #cbd5e1; /* slate-300 */
  --text: #0f172a; /* slate-900 */
  --muted: #475569; /* slate-600 */
  --ring: rgba(14,116,144,0.35);
}

/* Provider-based accent swap */
body[data-provider="AWS"] {
  --accent: #c2410c; /* orange-700 */
  --accent-border: #9a3412; /* orange-800 */
  --ring: rgba(194,65,12,0.35);
}
body[data-provider="Azure"] {
  /* Azure brand blue */
  --accent: #0078D4;
  --accent-border: #106EBE;
  --ring: rgba(0,120,212,0.45);
}
body[data-provider="GCP"] {
  /* Google Cloud blue */
  --accent: #1A73E8;
  --accent-border: #185ABC;
  --ring: rgba(26,115,232,0.40);
}
* { box-sizing: border-box; }
/* Let the document grow naturally; avoid constraining height to 100% which can
   cause the gradient layer to stop before the content ends and create a seam. */
html, body { margin: 0; }
/* Paint the gradient on the root element to avoid seams at the bottom of the viewport */
/* Draw a solid background on html, and place the gradient on a body pseudo-element
   so it scrolls with the document (no viewport seams when scrolling). */
html { background-color: var(--bg); min-height: 100%; }
body { position: relative; background: transparent; color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji", "Segoe UI Emoji"; z-index: 0; min-height: 100vh; }
body::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background-image: var(--bg-gradient); background-repeat: no-repeat; background-position: left top, right bottom; }
/* Ensure long pages are covered and reduce mobile seam artifacts when UI chrome collapses */
@supports (height: 100svh) {
  body { min-height: 100svh; }
  body::before { min-height: 100svh; }
}
.container { max-width: 72rem; margin: 0 auto; padding: 1rem; }
.header { display: flex; align-items: center; justify-content: space-between; margin: 0.5rem 0 1rem; gap: 0.75rem; }
h1 { font-size: 1.75rem; margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.toolbar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
/* Allow grid items to shrink to container width to avoid overflow on mobile */
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 1rem; padding: 1rem; box-shadow: 0 10px 30px rgba(0,0,0,0.15); backdrop-filter: blur(8px); }
.label { color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.text-lg { font-size: 1rem; }
.text-xl { font-size: 1.5rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
#prefix-lbl {
  width: 2rem;
}
.row { display: flex; align-items: center; justify-content: space-between; }
/* Reserve list items should be left-aligned with sensible spacing */
#reserved-list .row { justify-content: flex-start; gap: 0.75rem; }
/* Cloud reservation checkbox row left-aligned */
#cloud-row { justify-content: flex-start; gap: 0.5rem; }
.input, select { width: 100%; padding: 0.5rem 0.75rem; border-radius: 0.75rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); outline: none; transition: box-shadow 120ms, border-color 120ms, background 120ms; }
.input:focus, select:focus { border-color: var(--accent-border); box-shadow: 0 0 0 4px var(--ring); }
/* Hide number input spinners for cleaner prefix field */
.input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.input[type=number]::-webkit-outer-spin-button,
.input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.range { width: 100%; }
.range-wrap { position: relative; }
.range-bubble { position: absolute; top: -1.6rem; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 0.1rem 0.4rem; border-radius: 0.5rem; font-size: 0.75rem; transition: left 140ms ease, opacity 140ms ease; }

/* Buttons */
.btn { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 0.7rem; padding: 0.35rem 0.7rem; cursor: pointer; transition: transform 80ms, background 120ms, border-color 120ms, box-shadow 120ms; display: inline-flex; align-items: center; gap: 0.4rem; }
.btn.small { font-size: 0.6rem; line-height: 1; }
.btn:hover { background: var(--surface-alt); }
.btn:active { transform: translateY(1px); }
.btn.accent { background: linear-gradient(180deg, var(--accent), var(--accent-border)); border-color: var(--accent-border); color: #ffffff; }
.btn.accent:hover { filter: brightness(1.05); }
.btn:focus { outline: none; box-shadow: 0 0 0 4px var(--ring); border-color: var(--accent-border); }

/* Tiny pill chip */
.chip { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.5rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.chip .dotsep { width: 4px; height: 4px; border-radius: 999px; background: var(--muted); }
.icon { width: 14px; height: 14px; display: inline-block; vertical-align: middle; fill: currentColor; }
.icon.rotate { animation: rotateIcon 280ms ease; }
@keyframes rotateIcon { from { transform: rotate(0deg); } to { transform: rotate(180deg); } }

/* New two-phase icon spin to avoid snap-back */
.icon.spin-out { animation: iconOut 140ms ease forwards; }
.icon.spin-in { animation: iconIn 140ms ease forwards; }
@keyframes iconOut { from { transform: rotate(0deg); } to { transform: rotate(-90deg); } }
@keyframes iconIn { from { transform: rotate(90deg); } to { transform: rotate(0deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Bit cells and bracket bar */
.bits { display: flex; align-items: center; font-family: inherit; max-width: 100%; overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap; }
.octet { font-family: inherit; font-size: 0.95rem; display: inline-flex; flex-wrap: nowrap; white-space: nowrap; }
.dot { padding: 0 0.25rem; color: var(--muted); }
.bit { display: inline-block; width: 12px; height: 18px; line-height: 18px; text-align: center; border-radius: 4px; border: 1px solid var(--border); background: var(--cell-bg); transition: background 0.2s; color: var(--text); }
.bit.net { background: var(--accent); border-color: var(--accent-border); }
.barbit { display: inline-block; width: 12px; height: 6px; border-radius: 3px; margin: 0; background: var(--cell-bg); }
.barbit.net { background: var(--accent); }
/* Ensure bit and bracket items never wrap to a new line in flex rows */
.bit, .barbit, .dot { flex: 0 0 auto; }

/* Bitmap-specific bit styling: larger cells and distinct shading */
.bitmap .bit { width: 50px; height: 30px; line-height: 28px; padding: 0 6px; border-radius: 6px; background: #1e293b; border-color: #475569; font-weight: 600; }
.bitmap .bit.net { background: var(--accent); border-color: var(--accent-border); color: #ffffff; box-shadow: 0 0 0 2px var(--ring) inset; }

/* Card titles */
.section-title { font-size: 1.125rem; margin: 0; }
.mt-1{margin-top:0.25rem}.mt-2{margin-top:0.5rem}.mt-3{margin-top:0.75rem}.mt-4{margin-top:1rem}
.gap-1{gap:0.25rem}.gap-2{gap:0.5rem}.gap-3{gap:0.75rem}.gap-4{gap:1rem}
.py-4{padding-top:1rem;padding-bottom:1rem}
@keyframes bitflip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}
.animate-bitflip { animation: bitflip 220ms ease-in-out; }

/* Responsive grids */
@media (max-width: 768px){
  .header { position: sticky; top: 0; z-index: 60; background: var(--panel); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding-top: 0.5rem; padding-bottom: 0.5rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .sticky-controls { position: sticky; top: 0.5rem; z-index: 40; }
}

/* Toasts */
.toast-root { position: fixed; right: calc(0.75rem + env(safe-area-inset-right)); bottom: calc(0.75rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; }
.toast { position: relative; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 0.75rem; padding: 0.5rem 2rem 0.5rem 0.75rem; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.toast .toast-close { position: absolute; right: 0.35rem; top: 0.25rem; background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 0.25rem; border-radius: 0.35rem; }
.toast .toast-close:hover { color: var(--text); background: var(--surface-alt); }
.toast-enter { animation: toastIn 160ms ease-out; }
.toast-leave { animation: toastOut 160ms ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* Light theme overrides */
html[data-theme="light"] {
  --bg: #f8fafc; /* slate-50 */
  --bg-gradient: radial-gradient(1200px 700px at 20% 0%, rgba(14,116,144,0.06), transparent 60%), radial-gradient(1200px 700px at 80% 100%, rgba(2,132,199,0.05), transparent 60%);
  --panel: rgba(255,255,255,0.7);
  --border: #cbd5e1; /* slate-300 */
  --text: #0f172a; /* slate-900 */
  --muted: #475569; /* slate-600 */
  --ring: rgba(14,116,144,0.35);
  --surface: #fff;
  --surface-alt: #f1f5f9;
  --cell-bg: #e2e8f0;
  --cell-border: #cbd5e1;
}
html[data-theme="light"] .bitmap .bit { background: #e2e8f0; border-color: #cbd5e1; color: #0f172a; }
/* Keep accent button text readable in light mode as well */
html[data-theme="light"] .btn.accent { color: #ffffff; }

/* Lighter accent for Azure in light mode */
html[data-theme="light"] body[data-provider="Azure"] {
  /* Slightly lighter Azure tones in light theme */
  --accent: #118AD7;
  --accent-border: #0A75C2;
  --ring: rgba(0,120,212,0.30);
}
html[data-theme="light"] body[data-provider="GCP"] {
  --accent: #3584EA;
  --accent-border: #2C6FD1;
  --ring: rgba(53,132,234,0.28);
}

/* Light theme override for AWS ring to match contrast */
html[data-theme="light"] body[data-provider="AWS"] {
  --ring: rgba(234,88,12,0.30);
}

/* Typography polish */
body { line-height: 1.45; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }

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

/* Preset tiles (Base address presets) */
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0.5rem; }
.preset { position: relative; display: block; }
.preset > input { position: absolute; opacity: 0; pointer-events: none; }
.preset-card { display: flex; align-items: center; gap: 0.6rem; background: var(--surface); border-radius: 0.75rem; padding: 0.6rem 0.7rem; cursor: pointer; transition: box-shadow 120ms, background 120ms, transform 80ms; }
.preset-card:hover { background: var(--surface-alt); }
.preset-card:active { transform: translateY(1px); }
.preset-badge { width: 1.6rem; height: 1.6rem; border-radius: 0.5rem; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #ffffff; background: linear-gradient(180deg, var(--accent), var(--accent-border)); box-shadow: 0 0 0 1px var(--accent-border) inset; }
.preset-title { font-weight: 600; }
.preset-sub { color: var(--muted); font-size: 0.75rem; }
/* Focus-visible on the radio moves to card */
.preset > input:focus + .preset-card { box-shadow: 0 0 0 4px var(--ring); }
/* Checked state accent border and subtle ring */
.preset > input:checked + .preset-card { box-shadow: 0 0 0 2px var(--ring); }

/* Remove default UA border around fieldsets (notably around presets) */
fieldset { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
legend { padding: 0; }

/* Reserve space to prevent layout jump when toggling cloud reservations */
.reserved-block { min-height: 7rem; }
@media (max-width: 768px){ .reserved-block { min-height: 6rem; } }

/* Tablet (<=1024px): reduce 3-col grids to 2 */
@media (max-width: 1024px){
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Mobile and small tablets (<=768px) */
@media (max-width: 768px){
  .header { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .toolbar { width: 100%; justify-content: space-between; }
}

/* Narrow phones (<=640px) */
@media (max-width: 640px){
  .container { padding: 0.75rem; }
  h1 { font-size: 1.5rem; }
  .btn.small { font-size: 0.75rem; padding: 0.45rem 0.7rem; }
  .preset-grid { grid-template-columns: 1fr; }
  .range-bubble { top: -1.8rem; font-size: 0.8rem; }
}
/* Small phones (<=480px): scale bits to avoid scrolling */
@media (max-width: 480px){
  .bits { overflow-x: hidden; }
  .octet { font-size: 0.8rem; }
  .dot { padding: 0 0.15rem; font-size: 0.9em; }
  .bit { width: 9px; height: 16px; line-height: 16px; }
  .barbit { width: 9px; height: 5px; }
  span.label {font-size: 0.65rem;}
}

/* Very narrow devices (<=360px): minimize further to keep single line */
@media (max-width: 360px){
  .bits { overflow-x: hidden; }
  .octet { font-size: 0.7rem; }
  .dot { padding: 0 0.1rem; font-size: 0.85em; }
  .bit { width: 8px; height: 14px; line-height: 14px; }
  .barbit { width: 8px; height: 4px; }
}
