/* ==========================================================================
   KRUA.AI · Refined minimal aesthetic
   Calm · Spacious · Editorial typography meets modern SaaS
   ========================================================================== */

:root {
  --bg:           #FBFAF7;
  --surface:      #FFFFFF;
  --surface-2:    #F6F4EF;
  --surface-3:    #EFEBE3;

  --ink:          #0F0E0D;
  --ink-soft:     #4A4642;
  --ink-mute:     #8A847C;
  --ink-faint:    #B8B2A8;

  --line:         rgba(15,14,13,.06);
  --line-strong:  rgba(15,14,13,.12);

  --accent:       #C44523;
  --accent-soft:  rgba(196,69,35,.08);
  --accent-line:  rgba(196,69,35,.20);

  --ok:           #2D8B5B;
  --warn:         #B8841C;
  --err:          #C04A2D;
  --info:         #2D5BB8;

  --display:      'Anuphan','Inter',system-ui,-apple-system,sans-serif;
  --serif:        'Instrument Serif','Anuphan',Georgia,serif;
  --body:         'IBM Plex Sans Thai','Inter',system-ui,sans-serif;
  --mono:         'JetBrains Mono',ui-monospace,monospace;

  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    14px;

  --shadow-1:     0 1px 0 rgba(15,14,13,.04);
  --shadow-2:     0 1px 2px rgba(15,14,13,.04), 0 4px 12px -4px rgba(15,14,13,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.55;
  font-weight: 400;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent); color: #fff; }

h1, h2, h3, h4, h5 { font-family: var(--display); font-weight: 600; letter-spacing: -.018em; line-height: 1.18; color: var(--ink); }
.ital { font-family: var(--serif); font-style: italic; font-weight: 400; }
.mono { font-family: var(--mono); }

/* Shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 14px 16px;
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; margin-bottom: 8px; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--ink); color: #fff;
  display: grid; place-items: center;
  font-family: var(--serif); font-style: italic;
  font-weight: 600; font-size: 1rem; letter-spacing: -.02em;
}
.brand-name { display: flex; flex-direction: column; line-height: 1; }
.brand-name b { font-family: var(--display); font-weight: 700; color: var(--ink); font-size: .95rem; letter-spacing: -.015em; }
.brand-name b .ai-mini { margin-left: 3px; color: var(--accent); font-family: var(--display); font-weight: 700; font-size: .95rem; }
.brand-name small { font-family: var(--mono); font-size: .58rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: .12em; margin-top: 3px; }

.nav-group { margin-bottom: 18px; }
.nav-group .lbl { font-family: var(--mono); font-size: .58rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-mute); margin: 6px 0; padding: 0 10px; font-weight: 500; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: .86rem;
  color: var(--ink-soft);
  margin-bottom: 1px;
  transition: background .12s, color .12s;
  cursor: pointer;
  position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.on { background: var(--surface-2); color: var(--ink); font-weight: 500; }
.nav-link.on::before {
  content: ''; position: absolute; left: -14px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 16px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-link svg { width: 15px; height: 15px; opacity: .55; flex-shrink: 0; stroke-width: 1.6; }
.nav-link.on svg { opacity: .9; }
.nav-link .ai-tag {
  margin-left: auto;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--mono); font-size: .56rem; font-weight: 600;
  padding: 2px 5px; border-radius: 3px; letter-spacing: .08em;
}
.nav-link .nav-badge {
  margin-left: auto;
  background: #C04A2D; color: #fff;
  font-family: var(--mono); font-size: .58rem; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  letter-spacing: 0;
  animation: navBadgePulse 1.6s ease-in-out infinite;
}
@keyframes navBadgePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,74,45,.45); }
  50% { box-shadow: 0 0 0 5px rgba(192,74,45,0); }
}

.sidebar-foot { margin-top: auto; padding-top: 14px; font-family: var(--mono); font-size: .6rem; color: var(--ink-faint); text-align: center; letter-spacing: .04em; }

/* Main + topbar */
.main { background: var(--bg); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(251,250,247,.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-family: var(--display); font-size: 1.05rem; font-weight: 600; letter-spacing: -.012em; }
.topbar h1 small { display: block; font-family: var(--mono); font-size: .6rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: .12em; font-weight: 500; margin-top: 2px; }

.top-tools { display: flex; align-items: center; gap: 14px; }

/* Language switcher */
.lang-switch {
  display: inline-flex; align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px;
  font-family: var(--mono); font-size: .68rem;
}
.lang-switch a {
  padding: 5px 11px;
  border-radius: 99px;
  color: var(--ink-mute);
  letter-spacing: .04em;
  font-weight: 500;
  transition: color .12s, background .12s;
}
.lang-switch a.on { background: var(--ink); color: #fff; }
.lang-switch a:hover:not(.on) { color: var(--ink); }

/* User pill */
.user-pill { display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); }
.user-pill .ava { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-family: var(--display); font-weight: 600; font-size: .78rem; }
.user-pill b { font-size: .82rem; font-weight: 500; }
.user-pill small { display: block; font-family: var(--mono); font-size: .56rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: .1em; margin-top: 1px; }
.user-pill a.logout { font-family: var(--mono); font-size: .62rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: .08em; padding: 4px 8px; border-radius: 5px; margin-left: 6px; transition: color .12s, background .12s; }
.user-pill a.logout:hover { color: var(--accent); background: var(--accent-soft); }

.body { padding: 32px; max-width: 1280px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 32px; gap: 24px; flex-wrap: wrap; }
.page-head h2 { font-family: var(--display); font-size: 1.85rem; font-weight: 600; letter-spacing: -.025em; line-height: 1.1; }
.page-head .lead { color: var(--ink-soft); font-size: .92rem; max-width: 60ch; margin-top: 8px; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; transition: border-color .15s; }
.stat:hover { border-color: var(--line-strong); }
.stat .lbl { font-family: var(--mono); font-size: .6rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-mute); margin-bottom: 12px; font-weight: 500; }
.stat .val { font-family: var(--display); font-size: 1.7rem; font-weight: 600; letter-spacing: -.025em; line-height: 1; color: var(--ink); }
.stat .delta { font-family: var(--mono); font-size: .68rem; margin-top: 10px; color: var(--ink-mute); letter-spacing: .02em; }
.stat .delta.up { color: var(--ok); }
.stat .delta.down { color: var(--err); }

.ai-tag-mini { display: inline-block; color: var(--accent); font-family: var(--mono); font-size: .55rem; font-weight: 600; letter-spacing: .12em; margin-right: 6px; vertical-align: 1px; }

/* Cards & tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.card-head h3 { font-family: var(--display); font-size: 1.05rem; font-weight: 600; letter-spacing: -.012em; }
.card-head .more { font-family: var(--mono); font-size: .68rem; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; font-weight: 500; }
.card-head .more:hover { text-decoration: underline; }

.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th { text-align: left; padding: 10px 12px; font-family: var(--mono); font-size: .62rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-mute); font-weight: 500; border-bottom: 1px solid var(--line); }
.tbl td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--surface-2); }

/* Tags / status */
.pkg-tag { font-family: var(--mono); font-size: .58rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 3px 8px; border-radius: 4px; display: inline-block; }
.pkg-starter { background: var(--surface-3); color: var(--ink-soft); }
.pkg-professional { background: var(--accent-soft); color: var(--accent); }
.pkg-enterprise { background: rgba(184,132,28,.12); color: var(--warn); }

.status-dot { display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: .68rem; letter-spacing: .04em; }
.status-dot i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.status-dot.active i { background: var(--ok); }
.status-dot.trial i { background: var(--warn); }
.status-dot.past_due i, .status-dot.suspended i { background: var(--err); }
.status-dot.cancelled i { background: var(--ink-faint); }

/* Forms */
.field { margin-bottom: 18px; }
.field label { display: block; font-size: .82rem; font-weight: 500; color: var(--ink); margin-bottom: 6px; letter-spacing: -.005em; }
.field label .req { color: var(--accent); margin-left: 2px; }

.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=tel], .field input[type=number], .field input[type=url],
.field select, .field textarea, .ipt {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .9rem; font-family: var(--body); color: var(--ink);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
.field input:focus, .field select:focus, .field textarea:focus, .ipt:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(15,14,13,.06);
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.55; }
.field .hint { font-size: .76rem; color: var(--ink-mute); margin-top: 5px; }
.field .err { font-size: .76rem; color: var(--err); margin-top: 5px; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.checkrow { display: flex; align-items: center; gap: 10px; font-size: .88rem; cursor: pointer; padding: 4px 0; }
.checkrow input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: var(--radius); font-family: var(--body); font-weight: 500; font-size: .88rem; border: 1px solid transparent; transition: background .12s, color .12s, border-color .12s, transform .12s; cursor: pointer; letter-spacing: -.005em; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--ink-faint); }
.btn-danger { background: var(--surface); color: var(--err); border-color: rgba(192,74,45,.25); }
.btn-danger:hover { background: var(--err); color: #fff; border-color: var(--err); }
.btn-sm { padding: 6px 12px; font-size: .78rem; }

/* Filter chip */
.chip { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 99px; font-size: .8rem; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); transition: all .12s; font-weight: 500; }
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip-count { margin-left: 6px; font-family: var(--mono); font-size: .68rem; opacity: .65; }

/* Flash */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: .88rem; display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); }
.flash.ok { background: rgba(45,139,91,.06); border-color: rgba(45,139,91,.2); color: var(--ok); }
.flash.err { background: rgba(192,74,45,.06); border-color: rgba(192,74,45,.2); color: var(--err); }
.flash.info { background: rgba(184,132,28,.06); border-color: rgba(184,132,28,.2); color: var(--warn); }

/* AI insight */
.ai-insight { margin-top: 16px; background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--radius); padding: 14px 16px; }
.ai-insight-head { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: .62rem; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .12em; margin-bottom: 7px; }
.ai-insight-head svg { width: 13px; height: 13px; stroke-width: 1.8; }
.ai-insight p { font-size: .85rem; color: var(--ink-soft); line-height: 1.55; }

/* Menu grid */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.menu-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; transition: border-color .15s, transform .15s; display: flex; flex-direction: column; }
.menu-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }

.menu-card-img { aspect-ratio: 4/3; position: relative; background: var(--surface-3); overflow: hidden; }
.menu-card-img img { width: 100%; height: 100%; object-fit: cover; }
.menu-card-img .ph { position: absolute; inset: 0; background: linear-gradient(135deg, var(--surface-3), var(--ink-faint)); display: grid; place-items: center; color: #fff; font-family: var(--serif); font-style: italic; font-size: 1.4rem; opacity: .7; }
.menu-card-img .badge-rec { position: absolute; top: 10px; right: 10px; background: rgba(255,255,255,.9); backdrop-filter: blur(6px); color: var(--accent); width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; font-size: .85rem; }
.menu-card-img .badge-status { position: absolute; bottom: 10px; left: 10px; background: rgba(255,255,255,.9); backdrop-filter: blur(6px); color: var(--ink); font-family: var(--mono); font-size: .58rem; padding: 4px 8px; border-radius: 4px; text-transform: uppercase; letter-spacing: .08em; font-weight: 500; }
.menu-card-img .badge-status.off { background: rgba(192,74,45,.92); color: #fff; }
.menu-card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.menu-card-body .cat { font-family: var(--mono); font-size: .58rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-mute); font-weight: 500; }
.menu-card-body h4 { font-family: var(--display); font-size: 1rem; font-weight: 600; letter-spacing: -.012em; line-height: 1.2; }
.menu-card-body p { font-size: .78rem; color: var(--ink-soft); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.menu-card-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg); }
.menu-card-foot .price { font-family: var(--display); font-size: 1.05rem; font-weight: 600; color: var(--ink); letter-spacing: -.012em; }
.menu-card-foot .acts { display: flex; gap: 4px; }
.menu-card-foot .acts a, .menu-card-foot .acts button { width: 28px; height: 28px; border-radius: 5px; display: grid; place-items: center; color: var(--ink-mute); background: transparent; border: none; cursor: pointer; transition: background .12s, color .12s; }
.menu-card-foot .acts a:hover, .menu-card-foot .acts button:hover { background: var(--surface-2); color: var(--ink); }
.menu-card-foot .acts button.danger:hover { background: var(--accent-soft); color: var(--accent); }

.menu-add-card { background: transparent; border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 20px; text-align: center; gap: 8px; color: var(--ink); transition: background .15s, border-color .15s; min-height: 280px; }
.menu-add-card:hover { background: var(--accent-soft); border-color: var(--accent); }
.menu-add-card .upload-icon { width: 48px; height: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: grid; place-items: center; color: var(--accent); margin-bottom: 4px; }
.menu-add-card h4 { font-family: var(--display); font-size: 1rem; font-weight: 600; }
.menu-add-card p { font-size: .8rem; color: var(--ink-soft); }
.menu-add-card .formats { font-family: var(--mono); font-size: .6rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }

/* Upload zone */
.upload-zone { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--bg); padding: 28px 20px; text-align: center; transition: border-color .12s, background .12s; cursor: pointer; }
.upload-zone.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-zone .ico { width: 44px; height: 44px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: grid; place-items: center; color: var(--accent); margin: 0 auto 10px; }
.upload-zone .preview { margin-top: 14px; border-radius: var(--radius); max-width: 240px; margin-left: auto; margin-right: auto; border: 1px solid var(--line); }

/* Empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--ink-mute); }
.empty .empty-mark { font-size: 2.4rem; margin-bottom: 12px; opacity: .35; font-family: var(--serif); font-style: italic; }
.empty h3 { font-family: var(--display); font-size: 1.25rem; color: var(--ink); margin-bottom: 8px; font-weight: 600; }
.empty p { font-size: .9rem; margin-bottom: 22px; max-width: 40ch; margin-left: auto; margin-right: auto; }

/* Responsive */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .topbar { padding: 14px 18px; }
  .body { padding: 22px 18px; }
  .page-head h2 { font-size: 1.5rem; }
}
