:root {
  --bg: #f7f7f9;
  --card: #ffffff;
  --text: #1f2330;
  --muted: #6b7384;
  --border: #e3e6ed;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --success-bg: #d1fae5;
  --success-text: #065f46;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --muted-bg: #e5e7eb;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 10; }
.topbar-inner { height: 100%; padding: 0 24px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--primary); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--muted); }
.topbar-user .user-name { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--muted-bg); border: 1px solid var(--border); flex-shrink: 0; }
.user-avatar--placeholder { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.user-avatar--placeholder i { font-size: 18px; }
.topbar-user form { display: inline; margin: 0; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

/* ---------- Left sidebar ---------- */
.sidebar { position: fixed; top: 56px; left: 0; bottom: 0; width: 240px; background: #fff; border-right: 1px solid var(--border); padding: 16px 0; overflow-y: auto; z-index: 5; }
.sidebar-heading { padding: 16px 20px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav .nav-item { margin: 0; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: var(--muted); text-decoration: none; border-left: 3px solid transparent; font-size: 14px; }
.sidebar-nav .nav-link:hover { color: var(--text); background: #f5f6fa; text-decoration: none; }
.sidebar-nav .link-active .nav-link { color: var(--primary); background: #eef0ff; border-left-color: var(--primary); font-weight: 600; }
.sidebar-nav .nav-link i { width: 18px; text-align: center; color: inherit; }
.sidebar-nav .sidebar-label { flex: 1; }
.sidebar-nav .badge { background: var(--muted-bg); color: var(--muted); margin-left: auto; }

/* ---------- Main content ---------- */
/* Default: centered (used by the auth pages — login, forgot password, reset). */
.container { max-width: 1100px; margin: 24px auto; padding: 0 24px; }
/* Signed-in: shift right of the fixed sidebar and below the fixed topbar. */
body.has-sidebar .container { margin: 80px 24px 24px 264px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.page-header form { margin: 0; }

.breadcrumbs { margin-bottom: 4px; font-size: 13px; }
.breadcrumbs ol { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.breadcrumbs li { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.breadcrumbs li + li::before { content: "/"; color: var(--border); }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--primary); text-decoration: underline; }
.breadcrumbs [aria-current="page"] { color: var(--text); }

.muted { color: var(--muted); }
.empty-state { color: var(--muted); padding: 32px; background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; color: var(--text); }
.card:hover { text-decoration: none; border-color: var(--primary); }
.card-label { color: var(--muted); font-size: 14px; }
.card-value { font-size: 28px; font-weight: 600; }

.data-table { width: 100%; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); border-collapse: collapse; overflow: hidden; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #fafbfd; color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tr:last-child td { border-bottom: none; }
/* Actions column always pinned to the right edge of the table. */
.data-table th:last-child,
.data-table td:last-child,
.data-table .row-actions { text-align: right; white-space: nowrap; }
.row-action { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); }
.row-action i { font-size: 12px; }
.data-table code { background: var(--muted-bg); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--muted-bg); color: var(--muted); }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-muted { background: var(--muted-bg); color: var(--muted); }

.form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 24px;
}

/* Rows that should span both columns. */
.form > .errors,
.form > .fieldset,
.form > fieldset,
.form > .form-actions { grid-column: 1 / -1; }

/* SimpleForm row: <div class="input string required ..."><label>…</label><input>…</div> */
.form .input { display: flex; flex-direction: column; gap: 4px; margin: 0; min-width: 0; }
.form .input > label { font-weight: 500; font-size: 14px; color: var(--text); }
.form .input > label abbr { color: var(--error-text); text-decoration: none; margin-left: 2px; }
.form .input input[type="text"],
.form .input input[type="email"],
.form .input input[type="url"],
.form .input input[type="password"],
.form .input input[type="number"],
.form .input input[type="search"],
.form .input input[type="tel"],
.form .input input[type="date"],
.form .input input[type="datetime-local"],
.form .input input[type="time"],
.form .input select,
.form .input textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
}
.form .input input:focus,
.form .input select:focus,
.form .input textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}
.form .input .hint { color: var(--muted); font-size: 13px; }
.form .input .error { color: var(--error-text); font-size: 13px; }

/* Invalid state */
.form .input.field_with_errors input,
.form .input.field_with_errors select,
.form .input.field_with_errors textarea { border-color: var(--error-text); }

/* Boolean checkbox row: label wraps the checkbox + text */
/* Boolean row: checkbox + label inline; hint sits on its own line below. */
.form .input.boolean { flex-direction: column; align-items: flex-start; gap: 4px; }
.form .input.boolean > label { display: flex; align-items: center; gap: 8px; font-weight: normal; cursor: pointer; margin: 0; }
.form .input.boolean input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.form .input.boolean .hint { padding-left: 24px; }  /* align hint with label text, not checkbox */

/* Fieldset (grouped section) — also a 2-column grid for its inputs. */
.form .fieldset, .form fieldset.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 24px;
}
.form .fieldset > legend, .form fieldset.fieldset > legend {
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form .fieldset > .muted, .form fieldset.fieldset > .muted {
  margin: 0;
  grid-column: 1 / -1;
}

.form-actions { display: flex; gap: 8px; margin-top: 0; }
.form-actions .btn { padding: 10px 18px; font-size: 14px; }

.btn { display: inline-block; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; font-size: 14px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-ghost { background: transparent; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }

.errors { background: var(--error-bg); color: var(--error-text); padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.errors ul { margin: 4px 0 0 18px; }

.auth-card { max-width: 380px; margin: 80px auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.auth-card h1 { margin-top: 0; }
.auth-card hr { border: 0; border-top: 1px solid var(--border); }

/* Bootstrap utility shim — only the classes the engine login partial uses. */
.d-none { display: none !important; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.w-100 { width: 100%; }
.mt-3 { margin-top: 12px; }
.my-3 { margin-top: 12px; margin-bottom: 12px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.ml-1 { margin-left: 4px; }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.alert-danger { background: var(--error-bg); color: var(--error-text); }

/* Form-signin + form-password layout inside the auth-card. */
.auth-card .form-signin,
.auth-card .form-password { max-width: 100%; padding: 0; text-align: left; }

/* Headings and intro text in the password reset partials. */
.auth-card h1,
.auth-card h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.auth-card .intro { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

/* Engine submit button uses `module-gradient-button-inverted-system` instead
   of btn-primary. Style it (and the `#login-button` ID used on every form) to
   match the primary button. */
.auth-card #login-button,
.auth-card .module-gradient-button-inverted-system {
  background: var(--primary) !important;
  border: 1px solid var(--primary) !important;
  color: var(--primary-text) !important;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  margin-top: 12px;
}
.auth-card #login-button:hover,
.auth-card .module-gradient-button-inverted-system:hover { filter: brightness(0.95); }

/* devise/shared/_links override renders inside auth-card; constrain text size. */
.auth-card a { color: var(--primary); }
.auth-card p { margin: 12px 0; font-size: 14px; }
.auth-card .alert { font-size: 13px; }

/* All text-like inputs in the login form share the same look. */
.auth-card .simple_form .input { width: 100%; margin: 0 0 10px; }
.auth-card .simple_form .input input,
.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
  box-sizing: border-box;
}
.auth-card input[type="email"]:focus,
.auth-card input[type="password"]:focus,
.auth-card input[type="text"]:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}

/* Remember-me row: checkbox + inline label, no extra wrapping. */
.auth-card .login-fields.text-left {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 14px;
}
.auth-card .login-fields.text-left input[type="checkbox"] { margin: 0; width: auto; }
.auth-card .login-fields.text-left label { margin: 0; font-weight: normal; cursor: pointer; }

/* SimpleForm validation message styling (in case of error). */
.auth-card .simple_form .error { color: var(--error-text); font-size: 13px; margin-top: 4px; }
