:root {
  --bg: #0a0a0c;
  --surface: #131316;
  --surface-raised: #1a1a1f;
  --border: #2a2a30;
  --border-focus: #ff5c00;
  --text: #f2f2f4;
  --text-muted: #9b9ba8;
  --text-faint: #636370;
  --accent: #ff5c00;
  --accent-dim: rgba(255, 92, 0, 0.12);
  --accent-hover: #ff701f;
  --danger: #ff4757;
  --success: #3ddc84;
  --radius: 8px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  --max: 620px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ——— Nav ——— */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 10, 12, 0.92);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.75rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #0a0a0c;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.brand-mark-lg {
  width: 44px;
  height: 44px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.topbar-brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.topbar-brand strong {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-user {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.topbar-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.topbar-link:hover {
  color: var(--text);
}

.topbar-link.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.topbar-nav form {
  margin: 0 0 0 0.2rem;
}

.topbar-nav .btn-text {
  color: var(--text-muted);
}

/* ——— Layout ——— */

.container {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.5rem 1.15rem 3.5rem;
}

.page-header {
  margin-bottom: 1.35rem;
}

.page-header h1 {
  margin: 0 0 0.3rem;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

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

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ——— Cards ——— */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem;
  margin-bottom: 0.75rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.card.summary {
  background: var(--surface-raised);
}

/* ——— Forms ——— */

.field {
  margin-bottom: 0.9rem;
}

.field:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}

.hint {
  font-weight: 400;
  color: var(--text-faint);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s var(--ease);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}

textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.45;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.input-prefix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}

.input-prefix:focus-within {
  border-color: var(--border-focus);
}

.input-prefix span {
  display: flex;
  align-items: center;
  padding: 0 0.65rem;
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  border-right: 1px solid var(--border);
}

.input-prefix input {
  border: none;
  background: transparent;
  border-radius: 0;
}

.input-prefix input:focus {
  outline: none;
}

/* ——— Buttons ——— */

.btn-primary {
  width: 100%;
  padding: 0.75rem 1.15rem;
  margin-top: 0.25rem;
  background: var(--accent);
  color: #0a0a0c;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s var(--ease), opacity 0.15s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  padding: 0.45rem 0.8rem;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-text {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.55rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: color 0.15s var(--ease);
}

.btn-text:hover {
  color: var(--text);
}

.btn-small {
  padding: 0.38rem 0.65rem;
  font-size: 0.8125rem;
}

.btn-inline {
  width: auto;
  margin-top: 0.45rem;
}

.btn-danger {
  color: var(--danger) !important;
}

.btn-danger:hover {
  color: #ff6b7a !important;
}

/* ——— Presets ——— */

.presets-card {
  margin-bottom: 1.25rem;
}

.presets-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 0.2rem;
}

.presets-header h2 {
  margin: 0;
}

.presets-help {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.preset-save-panel {
  margin-bottom: 0;
  padding: 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.25s var(--ease), opacity 0.2s, padding 0.25s, margin 0.25s;
}

.preset-save-panel.is-open {
  max-height: 140px;
  opacity: 1;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
}

.preset-save-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.preset-save-row input {
  flex: 1;
  min-width: 130px;
}

.preset-save-row .btn-primary {
  width: auto;
  margin: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.8125rem;
}

.presets-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.presets-empty {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.875rem;
}

.preset-item,
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: border-color 0.15s var(--ease);
}

.preset-item:hover,
.history-item:hover {
  border-color: #3a3a42;
}

.preset-info,
.history-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}

.preset-info strong,
.history-item-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.preset-info span,
.history-item-sub {
  color: var(--text-muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* ——— VAT ——— */

.badge {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.1rem 0.4rem;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 3px;
  vertical-align: middle;
}

.summary-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.summary-row strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.summary-row.total {
  margin-top: 0.55rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  font-size: 0.9375rem;
  color: var(--text);
}

.summary-row.total strong {
  font-size: 1.125rem;
  color: var(--accent);
}

/* ——— Messages ——— */

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.65rem;
}

.success {
  color: var(--success);
  font-size: 0.875rem;
}

#preset-error,
#error-msg {
  text-align: left;
}

#preset-success {
  margin: 0 0 0.65rem;
}

/* ——— Auth ——— */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
}

.auth-header {
  margin-bottom: 1.5rem;
}

.auth-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.auth-header .subtitle {
  font-size: 0.875rem;
}

.auth-form .btn-primary {
  margin-top: 0.65rem;
}

.auth-error {
  margin: 0 0 0.85rem;
  padding: 0.6rem 0.75rem;
  background: rgba(255, 71, 87, 0.1);
  border: 1px solid rgba(255, 71, 87, 0.25);
  border-radius: var(--radius-sm);
}

/* ——— Admin ——— */

.admin-form {
  margin-top: 0;
}

.admin-message {
  margin: 0.75rem 0 0;
}

.user-stats {
  color: var(--text-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.user-row-disabled {
  opacity: 0.65;
}

.badge-disabled {
  background: rgba(255, 71, 87, 0.12);
  color: var(--danger);
}

.admin-user-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  min-width: 10rem;
}

.admin-user-actions form {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-table-wrap {
  overflow-x: auto;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.user-table th,
.user-table td {
  padding: 0.65rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.user-table th {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.user-table tbody tr:last-child td {
  border-bottom: none;
}

.user-date {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.user-actions {
  text-align: right;
}

.badge-muted {
  background: var(--surface-raised);
  color: var(--text-muted);
}

/* ——— Modal ——— */

.modal-overlay,
.pdf-preview {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-overlay[hidden],
.pdf-preview[hidden] {
  display: none;
}

.modal-backdrop,
.pdf-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.modal-box,
.pdf-preview-panel {
  position: relative;
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.modal-box-wide {
  width: min(460px, 100%);
}

.modal-title,
.pdf-preview-header h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-title span {
  color: var(--accent);
}

.modal-subtitle {
  margin: -0.5rem 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.modal-actions,
.pdf-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions .btn-primary,
.pdf-preview-actions .btn-primary {
  width: auto;
  margin: 0;
  padding: 0.55rem 1rem;
}

.login-ip-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 260px;
  overflow-y: auto;
}

.login-ip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.login-ip-address {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
}

.login-ip-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ——— History ——— */

.history-page-card {
  padding: 1rem;
}

.history-search {
  margin-bottom: 0.85rem;
}

.history-search input {
  width: 100%;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.history-select-all {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.history-select-all input,
.history-checkbox {
  width: auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.history-checkbox {
  flex-shrink: 0;
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.history-page-info {
  font-size: 0.8125rem;
  color: var(--text-muted);
  min-width: 9rem;
  text-align: center;
}

#history-success {
  margin-top: 0.65rem;
}

/* ——— PDF preview ——— */

.pdf-preview-panel {
  width: min(900px, 100%);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.pdf-preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
}

.pdf-preview-header h3 {
  margin: 0 0 0.15rem;
}

.pdf-preview-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  word-break: break-all;
}

#pdf-preview-frame {
  width: 100%;
  height: min(68vh, 720px);
  border: none;
  background: #fff;
}

.pdf-preview-actions {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

/* ——— Responsive ——— */

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

  .presets-header {
    flex-direction: column;
    align-items: stretch;
  }

  .preset-item,
  .history-item {
    flex-direction: column;
    align-items: stretch;
  }

  .preset-actions,
  .history-item .preset-actions {
    justify-content: flex-end;
  }

  .topbar-inner {
    flex-wrap: wrap;
  }

  .page-header h1 {
    font-size: 1.45rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
