:root {
  --bg-color: #0f0f0f;
  --panel-bg: #171717;
  --text-main: #ececec;
  --text-muted: #a1a1aa;
  --accent: #f4f4f5;
  --button-text: #111111;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --border: #2f2f2f;
  --hover-bg: rgb(255 255 255 / 5%);
  --soft-bg: rgb(255 255 255 / 3%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text-main);
  background: var(--bg-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 4px;
  padding: 8px 16px;
  color: var(--button-text);
  font-weight: 700;
  background: var(--accent);
  cursor: pointer;
}

button:hover {
  opacity: 0.9;
}

input,
select,
textarea {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--text-main);
  background: var(--bg-color);
}

input[type="date"] {
  position: relative;
  color-scheme: dark;
  cursor: pointer;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v4'/%3E%3Cpath d='M16 2v4'/%3E%3Crect width='18' height='18' x='3' y='4' rx='2'/%3E%3Cpath d='M3 10h18'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px 18px;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  margin: 0;
  cursor: pointer;
  opacity: 0;
}

html[data-theme-mode="light"] input[type="date"] {
  color-scheme: light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23171717' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v4'/%3E%3Cpath d='M16 2v4'/%3E%3Crect width='18' height='18' x='3' y='4' rx='2'/%3E%3Cpath d='M3 10h18'/%3E%3C/svg%3E");
}

textarea {
  min-height: 90px;
  resize: vertical;
}

a {
  color: var(--accent);
}

.view-panel[hidden] {
  display: none !important;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 60%);
  z-index: 999;
}

.overlay.open {
  display: block;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1000;
  width: 250px;
  padding: 20px;
  overflow-y: auto;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  transition: margin-left 0.25s ease;
}

.sidebar.collapsed {
  margin-left: -250px;
}

.brand {
  display: grid;
  place-items: center;
  gap: 12px;
  margin-bottom: 30px;
  text-align: center;
}

.brand-logo {
  display: block;
  width: min(160px, 100%);
  height: auto;
}

.brand h1 {
  margin: 0;
  color: var(--accent);
  font-size: 18px;
}

.sidebar-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-menu li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}

.sidebar-menu li:hover,
.sidebar-menu li.active {
  color: var(--text-main);
  font-weight: 700;
}

.sidebar-menu a {
  color: var(--danger);
  text-decoration: none;
}

.main-content {
  min-width: 0;
  padding: 20px;
  margin-left: 250px;
  transition: margin-left 0.25s ease;
}

.sidebar.collapsed + .main-content,
body:has(.sidebar.collapsed) .main-content {
  margin-left: 0;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  user-select: none;
}

.theme-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-toggle-track {
  position: relative;
  width: 44px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--soft-bg);
  cursor: pointer;
}

.theme-toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--accent);
  transition: transform 160ms ease;
}

.theme-toggle input:checked + .theme-toggle-track::after {
  transform: translateX(20px);
}

.theme-toggle input:focus-visible + .theme-toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header-row h2 {
  margin: 0;
  font-size: 22px;
}

#currentUserText,
.muted {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.hamburger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  color: var(--text-main);
  background: var(--panel-bg);
  border: 1px solid var(--border);
}

.stats-grid {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat-card {
  flex: 1;
  min-width: 170px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  background: var(--panel-bg);
}

.stat-card h3 {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.stat-card h1 {
  margin: 0;
  font-size: 32px;
}

.top-bar,
.settings-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 15px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.top-bar input,
.top-bar select,
.settings-form input,
.settings-form select {
  flex: 1;
  min-width: 170px;
}

.structured-form {
  display: grid;
  gap: 14px;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.form-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--soft-bg);
}

.form-section h4 {
  margin: 0;
  color: var(--accent);
  font-size: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.form-grid.two-column {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.form-grid input,
.form-grid select {
  width: 100%;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.table-wrapper,
.result-box {
  min-width: 0;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.table-wrapper h3,
.tab-content h3 {
  margin: 0 0 15px;
  font-size: 16px;
}

.scroll-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--accent);
  background: var(--bg-color);
}

tr:hover {
  background: var(--hover-bg);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.available {
  background: var(--success);
}

.badge.checked_out {
  background: var(--danger);
}

.badge.maintenance {
  background: var(--warning);
}

.badge.retired {
  background: #64748b;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 16px;
  color: var(--text-main);
  background: var(--soft-bg);
  font-weight: 700;
  text-decoration: none;
}

.btn-secondary {
  color: var(--text-main);
  background: var(--soft-bg);
  border: 1px solid var(--border);
}

.btn-delete {
  color: #fff;
  background: var(--danger);
}

.btn-add {
  color: var(--button-text);
  background: var(--success);
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  padding: 40px 10px;
  overflow-y: auto;
  align-items: flex-start;
  justify-content: center;
  background: rgb(0 0 0 / 70%);
}

.modal-content {
  display: flex;
  flex-direction: column;
  width: min(100%, 980px);
  max-height: 85vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-color);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.close-btn {
  padding: 0 10px;
  color: var(--text-main);
  font-size: 24px;
  background: transparent;
}

.modal-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}

.modal-tabs button {
  flex: 1;
  min-width: 130px;
  color: var(--text-muted);
  background: transparent;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}

.modal-tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--hover-bg);
}

.tab-content {
  display: none;
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.tab-content.active {
  display: block;
}

.model-grid,
.log-list,
.report-grid {
  display: grid;
  gap: 10px;
}

.model-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.model-card,
.log-item,
.report-link {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.report-link {
  color: var(--text-main);
  font-weight: 700;
  text-decoration: none;
}

.report-link:hover {
  color: var(--accent);
}

.model-card p,
.log-item p {
  margin: 4px 0;
  color: var(--text-muted);
}

.result-box {
  min-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

dialog {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  color: var(--text-main);
  background: var(--bg-color);
}

dialog::backdrop {
  background: rgb(0 0 0 / 70%);
}

.dialog-form {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.dialog-form h2 {
  margin: 0;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-form label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
}

.field-note {
  margin: -6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.setting-row strong {
  display: block;
  margin-bottom: 4px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-spacer {
  flex: 1;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.detail-card.full-width {
  grid-column: 1 / -1;
}

.detail-card h3 {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 15px;
}

.detail-card dl {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

.detail-card dt {
  color: var(--text-muted);
}

.detail-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.timeline {
  display: grid;
  gap: 10px;
}

.attachment-upload {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.attachment-upload input {
  flex: 1;
  min-width: 220px;
}

.attachment-list {
  display: grid;
  gap: 10px;
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-color);
}

.attachment-item p {
  margin: 4px 0 0;
  color: var(--text-muted);
}

.timeline-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-color);
}

.timeline-item p {
  margin: 4px 0 0;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.warning-text {
  color: var(--warning) !important;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 3000;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--button-text);
  background: var(--accent);
  opacity: 0;
  transform: translateY(10px);
  transition: 160ms ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(100%, 420px);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  background: var(--panel-bg);
  box-shadow: 0 24px 50px rgb(0 0 0 / 28%);
}

.login-logo {
  display: block;
  width: min(190px, 82%);
  height: auto;
  margin: 0 auto 22px;
}

.login-box h1 {
  margin: 0 0 8px;
}

.login-box p {
  color: var(--text-muted);
}

.login-btn {
  display: inline-block;
  width: 100%;
  margin-top: 0;
  padding: 12px 16px;
  border-radius: 6px;
  color: var(--button-text);
  background: var(--accent);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  transition: 0.2s;
}

.login-btn:hover {
  opacity: 0.9;
}

.google-btn-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.login-error {
  min-height: 22px;
  color: var(--danger) !important;
}

@media (max-width: 768px) {
  .sidebar {
    margin-left: -250px;
  }

  .sidebar.open {
    margin-left: 0;
  }

  .main-content {
    margin-left: 0;
    padding: 10px;
  }

  .header-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .stats-grid,
  .top-bar,
  .settings-form {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid,
  .form-grid.two-column {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .dialog-heading,
  .dialog-actions,
  .setting-row,
  .attachment-item {
    flex-wrap: wrap;
  }

  .stat-card,
  .top-bar input,
  .top-bar select,
  .top-bar button,
  .settings-form input,
  .settings-form select,
  .settings-form button,
  .form-actions button {
    width: 100%;
    min-width: 100%;
  }
}
