/* High-contrast theme variables */
:root {
  --bg: #ffffff;
  --bg-dark: #0f1115;
  --card: #ffffff;
  --card-dark: #141821;
  --text: #111111;
  --text-dark: #f1f3f5;
  --muted: #444444;
  --muted-dark: #a9b1bb;
  --border: #cfd4d9;
  --border-dark: #2b323b;
  --primary: #0d6efd;
  --slider-bg: #e9ecef;
  --slider-bg-dark: #1f2430;
}

/* Base */
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 24px;
  line-height: 1.5;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial;
  background: var(--bg);
  color: var(--text);
}
.main-header {
  background: transparent;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.main-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.main-nav ul {
  display: flex;
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.main-nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.main-nav a:hover { text-decoration: underline; }
.brand-link {
  color: inherit;
  text-decoration: none;
}
.brand-link:hover { text-decoration: underline; }
.container { max-width: 800px; margin: 0 auto; }
h1 { margin: 0 0 24px; text-align: center; }
h2 { margin: 0 0 16px; }

/* Card */
.calculator-box {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
}
.input-section { margin-bottom: 20px; }
.slider-section { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }

/* Input row (IP + Mask bits) */
.input-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}
.ip-field { flex: 1; max-width: 240px; }
.mask-field { flex: 0 0 140px; }
.netmask-field { flex: 0 0 180px; }

/* Form */
.field-group { margin: 0; }
label {
  display: block;
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.label-error {
  color: #dc3545;
}
input, select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  background: var(--card);
  color: var(--text);
}
input:focus, select:focus { 
  outline: 3px solid var(--primary); 
  outline-offset: 2px; 
  border-color: var(--primary); 
}
input[readonly] { background: #f8f9fa; cursor: not-allowed; }
select { cursor: pointer; }


/* Results */
.results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.result-field {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 40px;
  display: flex;
  align-items: center;
  font: 14px 'Courier New', monospace;
}

/* Status bar (slider) */
.status-bar-container { margin: 12px 0; }
.status-bar-wrapper {
  position: relative;
  height: 48px;
  background: var(--slider-bg);
  border-radius: 24px;
  overflow: hidden;
}
.status-bar-track { height: 100%; display: flex; }
.status-bar-fill, .status-bar-empty {
  height: 100%; display: flex; align-items: center; justify-content: center; transition: width .25s ease;
  font-weight: 600; font-size: 12px;
}
.status-bar-fill { background: linear-gradient(90deg, var(--primary), #28a745); color: #fff; }
.status-bar-empty { background: transparent; color: var(--muted); flex: 1; }
.status-bar-text { white-space: nowrap; }
.status-bar-slider { 
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; 
  -webkit-appearance: none; appearance: none; 
}
.status-bar-slider:focus { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Slider info (subnet/address counts under slider) */
.slider-info {
  display: flex;
  gap: 16px;
  margin-top: 16px;
}
.slider-info .field-group {
  flex: 1;
  margin: 0;
}
.slider-info .field-group:first-child {
  text-align: left;
}
.slider-info .field-group:last-child {
  text-align: right;
}


/* Binary Data Section */
.binary-data-section { 
  background: var(--card); 
  border: 1px solid var(--border);
  border-radius: 8px; 
  padding: 16px; 
  margin: 16px 0; 
}
.binary-title { 
  margin: 0 0 16px; 
  font-size: 16px; 
  font-weight: 600; 
  color: var(--text); 
}
.binary-table { 
  width: 100%; 
  border-collapse: collapse; 
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; 
  font-size: 13px; 
}
.binary-table tr { 
  border-bottom: 1px solid #e9ecef; 
}
.binary-table tr:last-child { 
  border-bottom: none; 
}
.binary-label { 
  padding: 8px 12px 8px 0; 
  font-weight: 500; 
  color: var(--muted); 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  font-size: 11px; 
  white-space: nowrap; 
  vertical-align: top; 
  width: 140px; 
}
.binary-value { 
  padding: 8px 0; 
  color: var(--text); 
  word-break: break-all; 
  user-select: all; 
  cursor: text; 
  background: none !important; 
  border: none !important; 
  border-radius: 0 !important; 
  box-shadow: none !important; 
}

/* Utilities */
.error { color: #dc3545; font-size: 13px; margin-top: 6px; }
.error:empty { display: none; }
.loading { opacity: .5; }
.footer { margin-top: 24px; text-align: center; opacity: .75; font-size: 13px; }

/* Buttons */
.btn-primary {
  display: inline-block;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(0.92); }

/* Mobile */
@media (max-width: 540px) {
  body { padding: 16px; }
  .calculator-box { padding: 16px; }
  .input-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .ip-field { max-width: none; }
  .mask-field { flex: none; }
  .netmask-field { flex: none; }
  .status-bar-wrapper { height: 44px; }
  input, select { height: 44px; }
  .slider-info { flex-direction: column; gap: 12px; }
  .slider-info .field-group:last-child { text-align: left; }
  .binary-table { font-size: 12px; }
  .binary-label { width: 120px; font-size: 10px; }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  body { background: var(--bg-dark); color: var(--text-dark); }
  .calculator-box { background: var(--card-dark); border-color: var(--border-dark); }
  label { color: var(--muted-dark); }
  input, select { background: #1b1f2a; border-color: var(--border-dark); color: var(--text-dark); }
  input:focus, select:focus { outline-color: var(--primary); border-color: var(--primary); }
  .result-field { background: var(--card-dark); color: var(--text-dark); border-color: var(--border-dark); }
  .status-bar-wrapper { background: var(--slider-bg-dark); }
  .status-bar-empty { color: var(--muted-dark); }
  .binary-data-section { background: var(--card-dark); border-color: var(--border-dark); }
  .binary-table tr { border-bottom-color: var(--border-dark); }
  .binary-value { color: var(--text-dark); }
  .main-nav a { color: var(--text-dark); }
  .main-nav a:hover { color: var(--text-dark); text-decoration: underline; }
  .binary-title { color: var(--text-dark); }
}