:root {
  color-scheme: dark;

  --background: #111827;
  --sidebar: #0b1220;
  --surface: #1f2937;
  --surface-light: #273449;
  --surface-hover: #303d52;
  --border: #374151;

  --text: #f3f4f6;
  --text-muted: #9ca3af;

  --primary: #5b8fd9;
  --primary-hover: #4b7fc7;

  --danger: #dc2626;
  --danger-hover: #b91c1c;

  --success-background: #123c2b;
  --success-border: #23855b;

  --error-background: #4a1d24;
  --error-border: #b9404d;

  --border-radius: 6px;
  --card-radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

h1,
h2,
h3 {
  margin-top: 0;
  line-height: 1.2;
}

h1 {
  margin-bottom: 8px;
  font-size: 1.8rem;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.2rem;
}

h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

p {
  margin-top: 0;
}

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

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

.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 20px;
}

.auth-main {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgb(91 143 217 / 18%), transparent 35%),
    var(--background);
}

.app-sidebar {
  width: 230px;
  min-height: 100vh;
  flex-shrink: 0;
  padding: 24px 18px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.app-sidebar h3 {
  margin-bottom: 24px;
  font-size: 1.1rem;
}

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

.app-sidebar li {
  margin-bottom: 8px;
}

.app-sidebar a {
  display: block;
  padding: 10px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--border-radius);
}

.app-sidebar a:hover {
  color: var(--text);
  background: var(--surface);
}

.app-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
}

.app-sidebar nav {
  flex: 1 1 auto;
}

.mobile-app-header,
.mobile-sidebar-backdrop {
  display: none;
}

.sidebar-user {
  position: relative;
  flex: 0 0 auto;
  margin-top: 20px;
}

.sidebar-user > summary {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  list-style: none;
}

.sidebar-user > summary::-webkit-details-marker {
  display: none;
}

.sidebar-user > summary:hover,
.sidebar-user[open] > summary {
  background: var(--surface-hover);
}

.sidebar-user-avatar {
  display: inline-flex;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 0.75rem;
  background: rgb(91 143 217 / 16%);
  border-radius: 50%;
}

.sidebar-user-copy {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  line-height: 1.2;
}

.sidebar-user-copy strong {
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-copy small {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.sidebar-user-chevron {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.sidebar-user-popup {
  position: absolute;
  right: 0;
  bottom: calc(100% + 7px);
  left: 0;
  z-index: 50;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  box-shadow: 0 14px 35px rgb(0 0 0 / 35%);
}

.sidebar-user-popup form,
.sidebar-user-popup button {
  width: 100%;
  margin: 0;
}

.sidebar-user-popup button {
  text-align: left;
}

section {
  margin-bottom: 20px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

form {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

label {
  display: block;
  font-weight: 600;
}

input[type="date"],
input[type="file"],
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
  min-height: 40px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
}

.login-card {
  display: grid;
  width: min(410px, 100%);
  gap: 20px;
  margin: 0;
  padding: 28px;
  box-shadow: 0 24px 70px rgb(0 0 0 / 30%);
}

.login-card h1,
.login-card p {
  margin-bottom: 0;
}

.login-eyebrow {
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-intro {
  margin-top: 6px;
  color: var(--text-muted);
}

.login-form {
  display: grid;
  align-items: stretch;
  gap: 14px;
}

.login-form input,
.login-form button {
  width: 100%;
}

input[type="file"] {
  max-width: 420px;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button {
  min-height: 40px;
  padding: 9px 16px;
  color: white;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  border: 0;
  border-radius: var(--border-radius);
}

button:hover {
  background: var(--primary-hover);
}

button:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.button-danger,
.delete-button {
  color: #f87171;
  background: var(--surface-light);
  border: 1px solid var(--border);
}

.button-danger:hover,
.delete-button:hover {
  color: #fca5a5;
  background: var(--surface-hover);
  border-color: #7f1d1d;
}

.button-danger:focus-visible,
.delete-button:focus-visible {
  outline-color: #f87171;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.form-field,
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.message,
.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid;
  border-radius: var(--border-radius);
}

.message-success,
.alert-success {
  background: var(--success-background);
  border-color: var(--success-border);
}

.message-error,
.alert-error {
  background: var(--error-background);
  border-color: var(--error-border);
}

.page-header {
  margin-bottom: 20px;
}

.page-header h1,
.page-header h2 {
  margin-bottom: 4px;
}

.page-header p {
  margin: 0;
  color: var(--text-muted);
}

.card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

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

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

th {
  color: var(--text);
  font-size: 0.9rem;
  background: #182233;
  white-space: nowrap;
}

td {
  color: #d1d5db;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 850px) {
  .app-layout {
    display: block;
  }

  body.mobile-sidebar-open {
    overflow: hidden;
  }

  .mobile-app-header {
    position: sticky;
    top: 0;
    z-index: 900;
    display: flex;
    min-height: 58px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 14px;
    background: rgb(11 18 32 / 96%);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
  }

  .mobile-app-header > span {
    max-width: 190px;
    font-size: 0.88rem;
    font-weight: 750;
    line-height: 1.15;
  }

  .mobile-menu-button {
    display: grid;
    width: 42px;
    min-height: 40px;
    flex: 0 0 42px;
    padding: 9px;
    place-content: center;
    gap: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
  }

  .mobile-menu-button:hover {
    background: var(--surface-hover);
  }

  .mobile-menu-button span {
    display: block;
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
    transition: transform 0.18s ease, opacity 0.18s ease;
  }

  .mobile-sidebar-open .mobile-menu-button span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .mobile-sidebar-open .mobile-menu-button span:nth-child(2) {
    opacity: 0;
  }

  .mobile-sidebar-open .mobile-menu-button span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1100;
    width: min(300px, 86vw);
    height: 100dvh;
    min-height: 0;
    padding: 22px 18px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 18px 0 45px rgb(0 0 0 / 35%);
  }

  .mobile-sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-sidebar h3 {
    margin-bottom: 24px;
  }

  .app-sidebar ul {
    display: block;
  }

  .app-sidebar li {
    margin-bottom: 8px;
  }

  .app-sidebar a {
    padding: 12px;
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: block;
    width: 100%;
    min-height: 100%;
    padding: 0;
    pointer-events: none;
    background: rgb(0 0 0 / 58%);
    border: 0;
    border-radius: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .mobile-sidebar-open .mobile-sidebar-backdrop {
    pointer-events: auto;
    opacity: 1;
  }

  .main-content {
    padding: 14px;
  }

  section,
  .card {
    padding: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .mobile-sidebar-backdrop,
  .mobile-menu-button span {
    transition: none;
  }
}

@media (max-width: 750px) {
  input[type="date"],
  input[type="file"],
  input[type="text"],
  input[type="number"],
  input[type="email"],
  select,
  textarea,
  button {
    width: 100%;
  }
}
