/*
 *  CSS reset
 */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-weight: inherit;
  font-style: inherit;
  font-size: 100%;
  font-family: inherit;
  vertical-align: middle;
}
:focus, .invalid {
  outline: none;
  box-shadow: none;
}
body {
  background-color: #111;
}
caption, th, td {
  text-align: left;
  font-weight: normal;
}
sup {
  vertical-align: super;
}
sub {
  vertical-align: sub;
}
sup, sub {
  font-size: smaller;
}

/*
 *  clearfix hack
 */

.clearfix::after {
  content: "";
  clear: both;
  display: table;
}

/*
 *  CSS Custom Properties (Variables)
 *  Shared across all themes - structural values only, not colors
 */

:root {
  /* Spacing scale - consistent across all themes */
  --space-xs: 0.25em;
  --space-sm: 0.5em;
  --space-md: 1em;
  --space-lg: 1.5em;
  --space-xl: 2em;
  --space-xxl: 3em;

  /* Z-index scale - layering management */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 500;
  --z-modal: 1000;
  --z-dialog: 10000;
  --z-tooltip: 10001;

  /* Transition durations - consistent UX timing */
  --transition-fast: 0.15s;
  --transition-normal: 0.3s;
  --transition-slow: 0.5s;

  /* Transition easing functions */
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* Font sizes */
  --font-size-tooltip: 0.9em;
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  /* Structural layout - not visual styling */
  --sidebar-width: 7em;
  --content-margin-left: 9em;
  --menu-padding-vertical: 0.5em;
  --table-padding: 0.3em;
  --input-padding-y: 0.3em;
  --input-padding-x: 0.6em;
  --button-padding-y: 0.3em;
  --button-padding-x: 0.6em;

  /* Map marker size - adjust this to change device marker size globally */
  --map-marker-size: 7px;
  --map-marker-mixed-extra: 4px; /* Additional size for mixed markers */
  --map-marker-number-gap: 5px; /* Gap between marker and number label */

  /* Device status colors - used for markers and borders */
  --device-status-online: #2ecc71;
  --device-status-offline: #f39c12;
  --device-status-inactive: #e74c3c;
  --device-status-unknown: #95a5a6;
  --device-status-destroyed: #34495e;
  --device-status-mixed: #9b59b6;

  /* Dialog system - common across all themes */
  --dialog-icon-size: 48px;
}

/*
 *  main document styles
 */

html { overflow-y: scroll; }

body {
  font-size: 90%;
  padding: 1em;
  line-height: 1em;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-weight: normal;
  margin: 0;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  scrollbar-color: var(--color-scrollbar-thumb) var(--color-scrollbar-track);
}

h3 {
  margin: 10px 0 10px 0;
  font-size: 1.2em;
  line-height: 1.2em;
}

h2 {
  font-size: 1.3em;
  line-height: 1.3em;
}

h1 {
  font-size: 1.5em;
  line-height: 3em;
}

hr {
  margin: 1em 0;
}

ul li {
  margin-left: 1em;
}

/* ruler between some elements */
hr.separator { margin: .7em 0; }

/* monospace font for class="mono" */
.mono { font-family: "Courier New", Courier, Monospace; }

fieldset, legend {
  border: 1px solid;
  border-radius: 0.5em;
}
fieldset {
  box-sizing: border-box;
  position: relative;
  display: inline-block;
  width: 100%;
  padding: 0.7em 1em 1.3em 1em;
}
legend {
  padding: 0.3em 0.5em;
}

input, select, button, textarea {
  box-sizing: border-box;
  border: 1px solid;
  border-radius: 0.4em;
  transition: 0.3s;
  font-family: inherit;
  font-size: inherit;
  accent-color: var(--color-primary);
}
button {
  cursor: pointer;
}
select:disabled, button:disabled, input[disabled], textarea[disabled] {
  cursor: not-allowed;
}

/* Form change detection: Ensure disabled save buttons show forbidden cursor */
button[disabled]:not([type="button"]):not([type="reset"]),
button[name="save"][disabled],
button[name="edit"][disabled],
button[type="submit"][disabled] {
  cursor: not-allowed !important;
}
input[type="checkbox"],
input[type="radio"] {
  vertical-align: middle;
  width: 1.2em;
  height: 1.4em;
}
input[type="radio"]         { margin:0 3px 3px; }
input[type="checkbox"].left { margin-left: 0;   }
input[type="number"]        { max-width: 5em;   }
input[type="file"]          { width: 18em;      }
select, button,
input[type="submit"],
input[type="reset"] {
  height: 1.9em;
}
@supports (-moz-appearance: none) { /* firefox */
  button.reload > div.center { font-size: 1.25em; }
}
select option {
  color: black;
  background-color: white;
}

textarea {
  text-indent: 5px;
  resize: none;
}
textarea.detail {
  width: 25em;
  height: 5em;
}
input[type="text"].detail {
  max-width: 30em;
  min-width: 20em;
}
input[type="date"],
input[type="password"],
input[type="text"],
input[type="number"] {
  height: 1.9em;
  border-radius: 0.4em;
  text-indent: 5px;
}
input.datetime {
  text-align: center;
  text-indent: 0;
}
#details-form select:disabled,
#details-form input[disabled],
#details-form textarea[disabled] {
  pointer-events: none;
  opacity: .5;
  cursor: default;
}

#details-form button:disabled {
  opacity: .5;
  cursor: not-allowed;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  margin-left: 3px;
  height: auto;
}
label {
  padding-right: 4px;
  text-align: right;
  display: inline-block;
}

.tiny   { width: 2em  !important; }
.small  { width: 5em  !important; }
.medium { width: 8em  !important; }
.big    { width: 12em !important; }

/* Config form specific styling */
.config-field { width: 24em !important; }
.huge   { width: 17em !important; }
.fill   { width: 100%; }

/*
 *  navigation
 */

.nav-button {
  width: 1.9em;
  font-size: 1.6em;
  cursor: pointer;
  opacity: 0.8;
  border: 0 none #0000;
}
.nav-button:hover {
  border: 0 none #0000;
  opacity: 1;
}
.nav-button i {
  margin: 0;
}

/*
 *  tables
 */

table {
  border-collapse: collapse;
  margin-top: 0.7em;
  width: 100%;
}
table.login {
  margin-bottom: 8px;
  width: 90%;
}
table.login td {
  border: 0;
}
table.simple th,
table.simple td {
  border: 0;
  padding: 1px;
}
table.gap th,
table.gap td {
  padding-right: 0.4em;
}
table.gap th:last-child,
table.gap td:last-child {
  padding-right: 0;
}
table.layout {
  background-color: #0000;
  border: .7em solid #0000;
  box-shadow: none;
}
table.layout, table#location {
  box-shadow: none;
}
table#location td {
  border: none;
}
table.shrink {
  max-width: 1em;
}
table.controls {
  background-color: #0000;
  box-shadow: none;
  border: 0 none #0000;
  overflow: visible;
}
table.controls td {
  vertical-align: top;
  padding: 0;
  border: 0;
  width: 40%;
  overflow: visible;
}
table.filter {
  border-radius: 0.4em;
}
table.filter th:first-child {
  border-top-left-radius: 0.4em;
}
table.filter th:last-child {
  border-top-right-radius: 0.4em;
}
th, td {
  border: 1px solid;
  padding: 3px;
  text-align: left;
  white-space: nowrap;       /* Prevent text from wrapping */
  overflow: hidden;          /* Hide overflowed content */
  text-overflow: ellipsis;   /* Add ellipsis for overflow */
}
th {
  font-weight: bold;
}
table td input[type="text"],
table td input[type=password] {
  width: 100%;
}
table th.standard {
  min-width: 3em;
  width: 10em;
}
table th.wide {
  min-width: 3em;
  width: 15em;
}
table th.grow {
  min-width: 7em;
  width: auto;
}
table th.minimum {
  width: 1em;
}
table th.action {
  min-width: 9em;
  width: 9em;
}

/*
 *  dashboard widgets
 */

.widget, .widget-flexible {
  flex: 1 1 calc(33.33% - 3em);
}
.widget, .widget-flexible, .widget-static {
  box-sizing: border-box;
  margin-bottom: 0;
}
.widget.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  background-color: black;
  overflow: hidden;
}
.widget.fullscreen fieldset {
  margin: 0;
  padding: 0;
  border: none;
}
.widget.fullscreen fieldset legend {
  display: none;
}
.widget.fullscreen fieldset div#map {
  height: 100vh;
  border: none;
  border-radius: 0;
}
.widget fieldset div#map {
  height: 21em;
  border-radius: .5em;
}
.leaflet-control-zoom, .leaflet-control-attribution {
  display: none;
}
.leaflet-container {
  background: black !important;
  border-radius: .5em;
}

.widget h2 {
  margin-top: 0;
}
@media (max-width: 768px) {
  .widget {
    flex: 1 1 100%; /* Full width */
  }
}

.device-stats td {
  text-align: center;
}
.progress-bar {
  position: relative;
  height: 1.2em;
  min-width: 4em;
  border: 1px solid;
  border-radius: .5em;
  overflow: hidden;
  transition: width 2s;
}
.progress {
  height: 100%;
}
.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  color: #000;
  font-weight: bold;
}

a.device, a.commit {
  color: inherit;
}

a.device {
  text-decoration: none;
}

a.device:hover {
  text-decoration: underline;
}

a.commit {
  font-family: monospace;
  text-decoration: underline;
  vertical-align: top;
  font-size: inherit;
}

/*
 *  positioning
 */

.dashboard, .flexbox {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--space-xl, 3em);
  row-gap: var(--space-xs, 1em);
}

div.content, .dashboard {
  margin-left: 8em; /* Match the menu width */
  padding: 1em 2em;
}

div.login {
  position: absolute;
  margin-top: 8em;
  margin-left: -12em;
  width: 24em;
  left: 50%;
}

div#version-changes ul {
  list-style-type: disc;
  margin-left: 2em;
}
div#version-changes li.private {
  font-style: italic;
}
div#build-log {
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 1.2em;
}

div.scrollable {
  line-height: 1.2em;
  min-width: 25em;
  max-height: 18em;
  overflow-y: auto;
}
table.fixed-header {
  margin-top: 0;
}
table.fixed-header thead {
  position: sticky;
  z-index: 1;
  top: 0;
}

/*
 *  alignments
 */

.ar {
  width: auto;
  margin-right: 0;
  margin-left: auto;
}

.fr { float: right; }
.fl { float: left;  }

.l { text-align: left;   }
.r { text-align: right;  }
.c { text-align: center; }

/*
 *  error message
 */

#message {
  font-weight: bold;
  font-size: 1.2em;
  color: red;
}
.fade-out {
  transition: opacity 2s ease-out;
  opacity: 0;
}

/*
 *  hourglass (spinner)
 */

.caption {
  position: absolute;
  width: 14em; height: 2.5em;
  left: 50%; top: 50%;
  margin: -2em 0 0 -7em;
  font-weight: 800; font-size: 2em;
}
.spin {
  z-index: 9990;
  position: fixed;
  visibility: hidden;
  left: 50%; top: 50%;
  width: 2em; height: 2em;
  margin: -1em 0 0 -1em;
  background: transparent;
  border: .5em solid #ffcfcf;
  border-top-color: #ff0000;
  border-radius: 50%;
  animation: spin linear .7s infinite;
  -webkit-animation: spin linear .7s infinite;
}
@-webkit-keyframes spin {
  100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
  100% { transform: rotate(360deg); }
}

/*
 *  menu
 */

.menu {
  width: 6em;
  color: white;
  position: fixed;
  top: 2em;
  left: 1em;
  font-size: 1.3em;
  line-height: 1.3em;
}
.menu ul {
  list-style-type: none;
  padding: 0;
}
.menu ul li {
  padding: .25em;
  padding-left: 0;
}
.menu ul li a {
  text-decoration: none;
  padding: 0;
  transition: .2s ease-out;
}
.menu ul li a:hover {
  padding: 0 .5em;
  transition: .2s ease-out;
}
.menu ul li a.active {
  font-weight: bold;
  border-left: 5px solid #fff;
  padding-left: 8px;
  padding-top: 6px;
  cursor: default;
}

footer {
  margin: 2em;
  padding: 1em 0 1em 1em;
  border-top: 1px solid #ddd8;
  opacity: .3;
}
footer a {
  text-decoration: none;
  color: inherit;
}

.remove-gap {
  display: flex;
  align-items: center;
}

.remove-gap input,
.remove-gap select {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  text-align: center;
  text-indent: 0;
}

.remove-gap button {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  margin-left: -1px; /* Prevents gaps */
}

.checkbox-container input[type="checkbox"] {
  height: 1em;
}

.popup, .tooltip {
  position: absolute;
  z-index: 9998;
  background: #eee;
  border: 1px solid black;
  color: black;
  font-size: var(--font-size-tooltip);
}

.popup {
  padding: 1em;
  border-radius: 1em;
  box-shadow: 2px 2px 10px rgba(0,0,0,0.5);
}

.tooltip {
  display: none;
  border-radius: 0.5em;
  padding: 0.5em;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
  pointer-events: none; /* Prevents interfering with other elements */
  max-width: 30em; /* Prevents the tooltip from being too wide */
  word-wrap: break-word;
  white-space: pre-wrap;
  font-family: monospace;
}

.hidden { display: none; }

/*
 *  reports
 */

.report-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
}

/* Default styles for iframes (side-by-side layout) */
#reportViewer {
  flex: 1 1 45%;
  min-width: 500px;
  max-width: 500px; /* Apply max-width when side-by-side */
  height: 70vh;
  background-color: #fffc;
  border: 1px solid #ccc;
}

#reportGenerator {
  flex: 1 1 45%;
  width: 100%;
  height: 70vh;
  background-color: #fffc;
  border: 1px solid #ccc;
}

/* Media query to apply styles when iframes are likely stacked */
/* Adjust the max-width breakpoint based on when your iframes typically wrap */
@media (max-width: 1550px) { /* You might need to fine-tune this breakpoint */
  #reportViewer {
    max-width: 100%; /* Remove max-width when stacked */
  }

  /* Optional: Adjust min-width and flex-basis for better stacking behavior on smaller screens */
  #reportViewer, #reportGenerator {
     min-width: 0; /* Allow shrinking below 480px if needed on very small screens */
     flex-basis: auto; /* Let flexbox determine basis when stacked */
     width: 100%; /* Ensure they take full width when stacked */
  }
}

/*
 *  Common Theme Element Styling
 *  Structural CSS shared across themes - themes override colors/effects via CSS variables
 */

/* Fieldsets and Legends */
fieldset {
  padding: var(--space-md);
  border-radius: 5px;
  margin: var(--space-md) 0;
}

legend {
  padding: 0.4em 0.8em;
  font-weight: bold;
}

/* Tables - common structure */
table.stripes tbody tr:nth-child(even),
table.clickable tbody tr:nth-child(even) {
  background-color: var(--color-bg-table-even, inherit);
}

table.clickable tbody tr {
  cursor: pointer;
}

table.clickable .row-selected {
  background-color: var(--color-table-row-selected, inherit) !important;
}

table.clickable tbody tr:not(.row-selected):hover {
  background-color: var(--color-table-row-hover, inherit) !important;
}

/* Progress bar structure */
.progress-bar {
  overflow: hidden;
  position: relative;
  height: 1.5em;
  margin: 0;
}

.progress-bar .progress {
  height: 100%;
}

.progress-bar .progress-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-weight: bold;
}

/* Content and Dashboard layout */
div.content, .dashboard {
  margin-left: var(--content-margin-left);
}

/*
 *  browser hacks (firefox)
 */

@supports (-moz-appearance: none) {
  button::-moz-focus-inner,
  input[type="file"] > input[type="button"]::-moz-focus-inner,
  input[type="color"]::-moz-focus-inner,
  input[type="button"]::-moz-focus-inner,
  input[type="submit"]::-moz-focus-inner,
  input[type="reset"]::-moz-focus-inner {
    padding: 0 !important;
    border: 0 none #000 !important;
  }
  [readonly] {
    cursor: default !important;
    user-select: none !important;
    -moz-user-select: none !important;
  }
}

/*
 * Dialog System
 * Note: Dialog styling is done via inline styles in dialog.js
 * Only the fade-in animation is defined here
 */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/*
 * Device Map Markers
 * Custom status-based device location markers for Leaflet maps
 * NOTE: Marker size controlled by --map-marker-size CSS variable (defined in :root)
 *       Also configurable in JavaScript: widget-device-locations.php (markerSize variable)
 */

.device-marker {
  width: var(--map-marker-size) !important;
  height: var(--map-marker-size) !important;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

/* Ensure individual device markers are always drawn on top of clusters */
.leaflet-marker-icon.device-marker {
  z-index: 1000 !important;
}

.device-marker.online {
  background-color: var(--device-status-online);
}

.device-marker.offline {
  background-color: var(--device-status-offline);
}

.device-marker.inactive {
  background-color: var(--device-status-inactive);
}

.device-marker.unknown {
  background-color: var(--device-status-unknown);
}

.device-marker.destroyed {
  background-color: var(--device-status-destroyed);
}

.device-marker.mixed {
  background-color: var(--device-status-mixed);
  width: calc(var(--map-marker-size) + var(--map-marker-mixed-extra)) !important;
  height: calc(var(--map-marker-size) + var(--map-marker-mixed-extra)) !important;
}

/* Leaflet popup styling with theme variables */
.leaflet-popup-content-wrapper {
  background-color: var(--color-bg-surface) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border) !important;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4) !important;
}

.leaflet-popup-content {
  width: auto !important;  /* Override Leaflet's inline width, let content decide */
  margin: 12px !important;
  font-family: inherit;
  color: var(--color-text-primary) !important;
}

.leaflet-popup-tip {
  background-color: var(--color-bg-surface) !important;
  border: 1px solid var(--color-border) !important;
  box-shadow: none !important;
}

/* Map popup header */
.map-popup-header {
  font-weight: bold;
  color: var(--color-text-heading);
  font-size: 14px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-primary);
}

/* Map popup grid container */
.map-popup-grid {
  display: grid;
  width: auto !important;
  gap: 8px;
  margin-top: 8px;
  padding-right: 8px;
  min-width: 500px;
  max-height: 400px;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 12px;
}

/* Map popup device item */
.map-popup-device-item {
  padding: 6px;
  border-left: 3px solid;
  padding-left: 8px;
  background-color: var(--color-bg-table);
  border-radius: 3px;
  transition: background-color 0.2s ease;
}

.map-popup-device-item:hover {
  background-color: var(--color-bg-table-even);
}

.map-popup-device-item a {
  font-weight: bold;
  color: var(--color-primary);
  text-decoration: none;
}

.map-popup-device-item a:hover {
  color: var(--color-primary-light);
  text-decoration: underline;
}

.map-popup-device-name {
  color: var(--color-text-primary);
  opacity: 0.7;
  font-size: 11px;
  display: block;
  margin-top: 2px;
}

/* Single device popup styling */
.map-popup-single {
  font-size: 13px;
  line-height: 1.6;
  min-width: 200px;
  width: auto !important;
}

.map-popup-single b {
  color: var(--color-text-heading);
}

.map-popup-single a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: bold;
}

.map-popup-single a:hover {
  color: var(--color-primary-light);
  text-decoration: underline;
}

/* Marker cluster styling - always drawn UNDER device markers */
.marker-cluster {
  z-index: 500 !important;  /* Lower than device markers (1000) */
}

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(155, 89, 182, 0.6) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: rgba(155, 89, 182, 0.8) !important;
}

/* Cluster text color for better readability */
.marker-cluster div span {
  color: #fff !important;
  font-weight: bold !important;
}
