/* Base styles */
:root {
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-bg: #f8fafc;
  --color-bg-card: #ffffff;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-success: #22c55e;
  --color-error: #ef4444;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  line-height: 1.5;
}

body {
  margin: 0;
  padding: 2rem;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* Navigation */
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);

  a {
    color: var(--color-text);
    text-decoration: none;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius);

    &:hover {
      background-color: var(--color-bg);
      text-decoration: none;
    }

    &.active {
      color: #fff;
      background-color: var(--color-primary);
    }
  }
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-weight: 600;
  line-height: 1.25;
}

h1 {
  font-size: 2rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.25rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

/* Links */
a {
  color: var(--color-primary);
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}

/* Lists */
ul,
ol {
  margin-top: 0;
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.25rem;
}

/* Cards */
.card {
  background: var(--color-bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
}

label {
  display: block;
  margin-bottom: 1rem;
  font-weight: 500;
  color: var(--color-text);
}

:is(
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  select,
  textarea
) {
  display: block;
  width: 100%;
  margin-top: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition:
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;

  &:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
  }
}

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

select {
  cursor: pointer;
}

/* Buttons */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  color: #fff;
  background-color: var(--color-primary);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease-in-out;

  &:hover {
    background-color: var(--color-primary-hover);
  }

  &:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
  }

  &[type="submit"] {
    margin-top: 0.5rem;
  }

  &.button-secondary {
    background-color: #475569;

    &:hover {
      background-color: #334155;
    }
  }
}

/* Utilities */
.text-muted {
  color: var(--color-text-muted);
}

.text-success {
  color: var(--color-success);
}

.text-error {
  color: var(--color-error);
}

.error {
  color: var(--color-error);
  background-color: #fef2f2;
  border: 1px solid var(--color-error);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.mt-1 {
  margin-top: 0.5rem;
}
.mt-2 {
  margin-top: 1rem;
}
.mt-3 {
  margin-top: 1.5rem;
}
.mb-1 {
  margin-bottom: 0.5rem;
}
.mb-2 {
  margin-bottom: 1rem;
}
.mb-3 {
  margin-bottom: 1.5rem;
}
.flex {
  display: flex;
}
.items-center {
  align-items: center;
}
.items-end {
  align-items: flex-end;
}
.justify-center {
  justify-content: center;
}
.justify-between {
  justify-content: space-between;
}
.grow {
  flex-grow: 1;
}

.button-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inline-form {
  display: inline;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;

  @media (max-width: 700px) {
    grid-template-columns: 1fr;
  }
}

.grid-span-2 {
  grid-column: span 2;

  @media (max-width: 700px) {
    grid-column: span 1;
  }
}

.mode-panel {
  border: 1px dashed var(--color-border);
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.mode-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  margin-bottom: 0;
}

.mode-select {
  max-width: 220px;
}

.mode-hint {
  margin: 0.4rem 0 0;
}

[x-cloak] {
  display: none !important;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;

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

  th {
    font-weight: 600;
    color: var(--color-text);
    background-color: var(--color-bg);
  }
}

/* HTMX loading indicator */
.htmx-request {
  opacity: 0.7;
  pointer-events: none;

  .htmx-indicator {
    display: inline;
  }
}

.htmx-indicator {
  display: none;
}

/* Accordion */
.accordion {
  margin-bottom: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg-card);
  box-shadow: var(--shadow);
  overflow: hidden;

  &[open] .accordion-header::before {
    transform: rotate(90deg);
  }

  .accordion-header {
    display: flex;
    align-items: center;
    /* justify-content: space-between; */
    padding: 1rem 1.5rem;
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    background: var(--color-bg-card);
    border: none;
    transition: background-color 0.15s ease-in-out;
    list-style: none;

    &::-webkit-details-marker {
      display: none;
    }

    &::before {
      content: "▶";
      display: inline-block;
      margin-right: 0.75rem;
      font-size: 0.75rem;
      transition: transform 0.2s ease-in-out;
    }

    &:hover {
      background: var(--color-bg);
    }
  }

  .accordion-content {
    padding: 0 1.5rem 1.5rem;
  }
}

/* Language Toggle */
.language-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;

  .language-select {
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
    color: var(--color-text);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    box-shadow: var(--shadow);
  }
}
