:root {
  /* Brand primary, replaceable with Ant Design colorPrimary */
  --primary: #5d4436;
  --primary-hover: #7a5946;
  --primary-active: #453126;
  --primary-bg: #f7f0ec;
  --primary-bg-hover: #f1e5de;
  --primary-border: #d8c0b2;

  /* Status palette */
  --success: #52c41a;
  --success-text: #237804;
  --success-bg: #f6ffed;
  --success-border: #b7eb8f;

  --warning: #faad14;
  --warning-text: #d48806;
  --warning-bg: #fffbe6;
  --warning-border: #ffe58f;

  --error: #ff4d4f;
  --error-text: #cf1322;
  --error-bg: #fff2f0;
  --error-border: #ffccc7;

  --info: #1677ff;
  --info-text: #0958d9;
  --info-bg: #e6f4ff;
  --info-border: #91caff;

  /* Text */
  --text: rgba(0, 0, 0, 0.88);
  --text-secondary: rgba(0, 0, 0, 0.65);
  --text-tertiary: rgba(0, 0, 0, 0.56);
  --text-quaternary: rgba(0, 0, 0, 0.25);

  /* Surfaces */
  --bg-layout: #f5f5f5;
  --bg-container: #ffffff;
  --bg-elevated: #ffffff;
  --fill-alter: #fafafa;
  --fill-secondary: rgba(0, 0, 0, 0.06);
  --fill-tertiary: rgba(0, 0, 0, 0.04);

  /* Lines */
  --border: #d9d9d9;
  --border-secondary: #f0f0f0;
  --split: rgba(5, 5, 5, 0.06);

  /* Shape */
  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03), 0 1px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px 0 rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);

  /* Type */
  --font: "Noto Sans Thai", "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* Controls */
  --control-h: 36px;
  --control-h-lg: 40px;
  --control-h-sm: 28px;
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--primary-bg-hover);
  color: var(--text);
}

html {
  scroll-behavior: smooth;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: var(--bg-layout);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5714;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
dl,
dd,
figure {
  margin: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

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

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.icon {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  vertical-align: -0.15em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 200;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
}

.skip-link:focus {
  top: 8px;
}

.tnum {
  font-variant-numeric: tabular-nums;
}

/* Header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-container);
  border-bottom: 1px solid var(--border-secondary);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1280px;
  min-height: 64px;
  margin: 0 auto;
  padding: 0 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
}

.brand img {
  display: block;
  width: auto;
  height: 24px;
}

.header-divider {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--border-secondary);
}

.header-product {
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.header-link {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: none;
}

.header-link:hover {
  background: var(--fill-tertiary);
  color: var(--text);
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
}

.lang-btn:hover {
  background: var(--fill-tertiary);
  color: var(--text);
}

.lang-btn .lang-label {
  min-width: 20px;
  text-align: center;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--border-secondary);
  color: var(--text);
  font-size: 14px;
}

.user-chip .icon {
  color: var(--text-tertiary);
}

.user-role {
  color: var(--text-tertiary);
  font-size: 12px;
}

/* Layout */

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 32px;
  border-top: 1px solid var(--border-secondary);
  color: var(--text-tertiary);
  font-size: 12px;
}

.app-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.app-footer a {
  color: var(--text-tertiary);
}

.app-footer a:hover {
  color: var(--primary);
}

/* Page head */

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

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-tertiary);
  font-size: 12px;
}

.breadcrumb a {
  color: var(--text-tertiary);
}

.breadcrumb a:hover {
  color: var(--primary);
}

.page-head-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.page-head h1 {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.4;
}

.page-sub {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Card */

.card {
  background: var(--bg-container);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-secondary);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.card-extra {
  color: var(--text-secondary);
  font-size: 14px;
}

.card-body {
  padding: 20px;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

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

.btn:disabled {
  border-color: var(--border);
  background: var(--fill-tertiary);
  color: var(--text-quaternary);
  cursor: not-allowed;
}

.btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
  color: #fff;
}

.btn-primary:disabled {
  border-color: var(--border);
  background: var(--fill-secondary);
  color: var(--text-quaternary);
}

.btn-danger {
  border-color: var(--error-border);
  background: var(--bg-container);
  color: var(--error-text);
}

.btn-danger:hover {
  border-color: var(--error);
  color: var(--error);
}

.btn-danger:disabled {
  border-color: var(--border);
  color: var(--text-quaternary);
}

.btn-text {
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.btn-text:hover {
  border-color: transparent;
  background: var(--fill-tertiary);
  color: var(--text);
}

.btn-link {
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
}

.btn-link:hover {
  background: transparent;
  color: var(--primary-hover);
}

.btn-lg {
  height: var(--control-h-lg);
  padding: 0 20px;
  font-size: 15px;
}

.btn-sm {
  height: var(--control-h-sm);
  padding: 0 10px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

/* Form controls */

.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-h);
  padding: 4px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--primary-border);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(93, 68, 54, 0.12);
}

.input[readonly] {
  background: var(--fill-alter);
  color: var(--text-secondary);
  cursor: default;
}

.input[readonly]:hover {
  border-color: var(--border);
}

.input::placeholder,
.textarea::placeholder {
  color: rgba(0, 0, 0, 0.55);
}

.input-lg,
.select-lg {
  height: var(--control-h-lg);
  padding: 4px 12px;
  font-size: 15px;
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: 8px 11px;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%238c8c8c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

.input-affix {
  position: relative;
  flex: 1 1 220px;
  min-width: 0;
}

.input-affix .icon {
  position: absolute;
  top: 50%;
  left: 11px;
  color: var(--text-tertiary);
  transform: translateY(-50%);
  pointer-events: none;
}

.input-affix .input {
  padding-left: 32px;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-item > label {
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

.form-item:has(input[required], select[required], textarea[required]) > label::after {
  content: "*";
  margin-left: 2px;
  color: var(--error);
}

.form-hint {
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.5;
}

.form-error {
  color: var(--error);
  font-size: 14px;
  line-height: 1.4;
}

/* Tags and status */

.tag,
.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--fill-alter);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}

.tag .icon {
  width: 12px;
  height: 12px;
}

.tag--primary {
  border-color: var(--primary-border);
  background: var(--primary-bg);
  color: var(--primary);
}

.tag--success {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success-text);
}

.tag--warning {
  border-color: var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning-text);
}

.tag--error {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
}

.status--review {
  border-color: var(--info-border);
  background: var(--info-bg);
  color: var(--info-text);
}

.status--fix {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
}

.status--done {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success-text);
}

.status--draft {
  border-color: var(--border);
  background: var(--fill-alter);
  color: var(--text-secondary);
}

/* Alerts */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--info-border);
  border-radius: var(--radius);
  background: var(--info-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5714;
}

.alert .icon {
  margin-top: 3px;
  color: var(--info);
}

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

.alert--success .icon {
  color: var(--success);
}

.alert--warning {
  border-color: var(--warning-border);
  background: var(--warning-bg);
}

.alert--warning .icon {
  color: var(--warning);
}

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

.alert--error .icon {
  color: var(--error);
}

/* Badge */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--error);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  line-height: 20px;
}

/* Empty */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 32px 16px;
  color: var(--text-tertiary);
  font-size: 14px;
  text-align: center;
}

.empty .icon {
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
  color: var(--text-quaternary);
}

/* Icon button */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
}

.icon-btn:hover {
  background: var(--fill-tertiary);
  color: var(--text);
}

/* Focus */

.btn:focus-visible,
.lang-btn:focus-visible,
.icon-btn:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn:focus-visible,
.lang-btn:focus-visible,
.icon-btn:focus-visible {
  outline-offset: 1px;
}

@media (max-width: 720px) {
  .header-inner {
    min-height: 56px;
    padding: 0 16px;
    gap: 8px;
  }

  .brand img {
    height: 20px;
  }

  .header-product,
  .header-divider,
  .header-link {
    display: none;
  }

  .app-main {
    padding: 16px 16px 40px;
  }

  .page-head-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-head h1 {
    font-size: 20px;
  }

  .app-footer {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }

  .user-chip span {
    display: none;
  }

  .user-chip {
    padding: 0 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition: none !important;
    animation: none !important;
  }
}
