:root {
  color-scheme: light;
  --bg: #f4f0e5;
  --surface: #fffdf7;
  --surface-2: #f7f2e6;
  --text: #263523;
  --muted: #6f765d;
  --line: #ddd2bb;
  --primary: #2f7d32;
  --primary-strong: #205822;
  --primary-soft: #dfeeda;
  --accent: #a4512c;
  --warning: #c9851e;
  --sidebar: #17381f;
  --sidebar-active: #275a30;
  --shadow: 0 12px 30px rgba(70, 55, 31, 0.12);
}

body.dark {
  color-scheme: dark;
  --bg: #151b12;
  --surface: #202719;
  --surface-2: #2a321f;
  --text: #f0ead8;
  --muted: #b7b18f;
  --line: #3e4a32;
  --primary: #78b95f;
  --primary-strong: #b5df98;
  --primary-soft: #293f24;
  --accent: #e1995f;
  --warning: #e3b84f;
  --sidebar: #0f2615;
  --sidebar-active: #24472a;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  border: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  width: 260px;
  height: 100vh;
  flex: 0 0 260px;
  padding: 22px 18px;
  background: var(--sidebar);
  color: #f8fafc;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f3d27a;
  color: #17381f;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
}

.brand p,
.section-heading p,
.panel p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.brand p {
  color: #c9d6b8;
  font-size: 0.86rem;
}

.nav-links {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

.nav-link {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: #e2ead7;
  text-align: left;
  cursor: pointer;
}

.nav-link:hover,
.nav-link.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

.main {
  width: calc(100% - 260px);
  padding: 24px;
}

.topbar,
.section-heading,
.panel-header,
.topbar-actions,
.profile,
.setting-row {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar h2,
.section-heading h3,
.panel h3 {
  margin: 0;
}

.topbar h2 {
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.topbar-actions {
  gap: 10px;
}

.search-wrap {
  position: relative;
  min-width: min(320px, 36vw);
}

.search-wrap span {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  height: 42px;
  padding: 0 12px 0 66px;
}

input,
select,
textarea {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

textarea {
  padding-top: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.icon-button,
.profile-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.icon-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  cursor: pointer;
}

.profile {
  gap: 9px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
}

.profile-avatar {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.panel,
.item-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
}

.metric-label,
.item-meta,
.activity-time,
.badge {
  color: var(--muted);
  font-size: 0.84rem;
}

.metric-card strong {
  display: block;
  margin: 8px 0;
  font-size: 2rem;
}

.metric-card small {
  color: var(--primary);
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.primary-action,
.ghost-button,
.danger-button,
.inline-form button,
.chat-form button,
.form-grid button,
.announcement-form button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.primary-action,
.inline-form button,
.chat-form button,
.form-grid button,
.announcement-form button {
  background: var(--primary);
  color: #ffffff;
}

.primary-action:hover,
.inline-form button:hover,
.chat-form button:hover,
.form-grid button:hover,
.announcement-form button:hover {
  background: var(--primary-strong);
}

.ghost-button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.danger-button {
  background: #f6dfcf;
  color: #8a3219;
}

body.dark .danger-button {
  background: #4a2418;
  color: #ffd2bd;
}

.bar-chart {
  height: 260px;
  display: flex;
  align-items: end;
  gap: 12px;
  padding-top: 20px;
}

.bar-group {
  min-width: 38px;
  flex: 1;
  display: grid;
  gap: 8px;
  align-items: end;
}

.bar {
  min-height: 10px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--primary), #d7a642);
}

.bar-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.inline-form,
.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 12px;
}

.task-list,
.activity-list,
.notice-list,
.chat-panel {
  display: grid;
  gap: 10px;
}

.task-item,
.activity-item,
.notice-card,
.chat-message,
.item-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.task-item.done span {
  color: var(--muted);
  text-decoration: line-through;
}

.task-item button,
.row-action {
  border-radius: 7px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

.activity-item {
  padding: 12px;
}

.activity-item strong {
  display: block;
  margin-bottom: 4px;
}

.notice-card {
  padding: 14px;
}

.notice-card h4 {
  margin: 0 0 6px;
}

.notice-card p {
  margin: 0 0 8px;
  color: var(--text);
}

.notice-card .row-action {
  display: block;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.table-panel {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

body.compact th,
body.compact td {
  padding: 8px 10px;
}

.status {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.status.Active {
  background: #dcfce7;
  color: #166534;
}

.status.Pending {
  background: #fef3c7;
  color: #92400e;
}

.status.Inactive {
  background: #e5decc;
  color: #554f40;
}

body.dark .status.Active {
  background: #143d2a;
  color: #86efac;
}

body.dark .status.Pending {
  background: #43330f;
  color: #fde68a;
}

body.dark .status.Inactive {
  background: #303846;
  color: #cbd5e1;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.item-card {
  padding: 16px;
}

.item-card h3 {
  margin-bottom: 8px;
}

.item-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.item-price {
  font-size: 1.35rem;
  font-weight: 800;
}

.stock-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stock-controls button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
}

.assistant-shell {
  display: grid;
  gap: 12px;
  min-height: min(680px, calc(100vh - 150px));
}

.chat-panel {
  min-height: 470px;
  max-height: 62vh;
  overflow-y: auto;
  align-content: start;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(47, 125, 50, 0.07), transparent 210px),
    var(--surface);
  scroll-behavior: smooth;
}

.chat-message {
  max-width: min(720px, 90%);
  padding: 13px 15px;
  box-shadow: 0 8px 24px rgba(40, 54, 35, 0.08);
}

.chat-message p {
  margin: 6px 0 0;
  line-height: 1.55;
}

.message-role {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.chat-message.user {
  justify-self: end;
  background: var(--primary);
  color: #ffffff;
}

.chat-message.user .message-role {
  color: rgba(255, 255, 255, 0.76);
}

.chat-message.assistant {
  justify-self: start;
  background: var(--surface-2);
}

.chat-form {
  position: sticky;
  bottom: 0;
  margin-bottom: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chat-form input {
  border-color: transparent;
  background: var(--surface-2);
}

.chat-form button:disabled,
.chat-form input:disabled {
  cursor: not-allowed;
  opacity: 0.66;
}

.typing-message {
  width: max-content;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 25px;
  margin-top: 8px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingPulse 0.95s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.announcement-form {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 10px;
  margin-bottom: 18px;
}

.announcement-form textarea {
  grid-column: 1 / -1;
}

.notice-list.large {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.setting-row {
  justify-content: space-between;
  gap: 16px;
}

.switch {
  position: relative;
  display: inline-flex;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: 0.2s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  transition: 0.2s ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(22px);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  .metric-grid,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .notice-list.large {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .item-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  body {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 16px;
  }

  .nav-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    width: 100%;
    padding: 16px;
  }

  .topbar,
  .section-heading,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-wrap {
    min-width: 100%;
  }

  .profile {
    width: max-content;
  }

  .metric-grid,
  .form-grid,
  .item-grid,
  .settings-grid,
  .announcement-form {
    grid-template-columns: 1fr;
  }

  .inline-form,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .bar-chart {
    gap: 7px;
  }
}
