:root {
  --cream: #fff9f4;
  --paper: #fffdfb;
  --white: #ffffff;
  --ink: #3e3a39;
  --muted: #958d89;
  --line: #eee5df;
  --coral: #e87968;
  --coral-dark: #ca5f51;
  --coral-soft: #fff0ec;
  --mint: #e3f1e8;
  --green: #4f8b6d;
  --yellow: #fff1c9;
  --input: #fffdfa;
  --soft-green: #f8fcf8;
  --soft-yellow: #fffaf0;
  --summary: #fffaf8;
  --shadow: 0 14px 34px rgba(127, 87, 68, .08);
}

* { box-sizing: border-box; }
html { background: var(--cream); }
body { margin: 0; background: var(--cream); color: var(--ink); font-family: 'Sarabun', sans-serif; font-size: 16px; line-height: 1.55; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.is-hidden, .hidden { display: none !important; }

/* Auth: one clear action, generous spacing, friendly but quiet visual language. */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background: var(--cream); }
.auth-card { width: min(430px, 100%); padding: 42px; background: var(--white); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; color: var(--coral-dark); font: 700 13px 'DM Sans'; letter-spacing: 1.3px; margin-bottom: 54px; }
.brand-monogram { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px 12px 12px 4px; background: var(--coral); color: white; font-weight: 700; letter-spacing: 0; }
.auth-kicker, .section-kicker { margin: 0 0 10px; color: var(--coral-dark); font: 700 11px 'DM Sans'; letter-spacing: 1.2px; }
.auth-card h1 { margin: 0; font-size: 32px; letter-spacing: -.8px; line-height: 1.15; }
.auth-description { margin: 10px 0 28px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.auth-form { display: grid; gap: 16px; }
.auth-field span, .field > span { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 700; }
.auth-field input, .field input, .field textarea, .field select { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--input); color: var(--ink); outline: none; transition: border-color .16s, box-shadow .16s; }
.auth-field input { height: 48px; padding: 0 14px; font-size: 14px; }
.auth-field input:focus, .field input:focus, .field textarea:focus, .field select:focus { border-color: var(--coral); box-shadow: 0 0 0 4px var(--coral-soft); }
.auth-submit, .primary-button { border: 0; border-radius: 12px; background: var(--coral); color: #fff; padding: 12px 18px; font-size: 15px; font-weight: 700; box-shadow: 0 6px 12px rgba(232, 121, 104, .22); transition: transform .16s, background .16s; }
.auth-submit:hover, .primary-button:hover { background: var(--coral-dark); transform: translateY(-1px); }
.auth-submit:disabled, .primary-button:disabled { cursor: wait; opacity: .65; transform: none; }
.auth-message { min-height: 21px; margin: 13px 0 0; color: #bd5b4e; font-size: 13px; }
.auth-switch { display: flex; justify-content: center; gap: 6px; margin-top: 24px; color: var(--muted); font-size: 13px; }
.auth-switch button { border: 0; padding: 0; background: transparent; color: var(--coral-dark); font-weight: 700; }
.auth-note { margin: 28px 0 0; color: #aaa19b; text-align: center; font-size: 12px; }

/* App shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 266px; display: flex; flex-direction: column; padding: 30px 20px 22px; background: var(--paper); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px; margin-bottom: 36px; }
.sidebar .brand-monogram { width: 38px; height: 38px; background: var(--coral); }
.brand-name { color: var(--ink); font-size: 19px; font-weight: 700; line-height: 1; }
.brand-sub { margin-top: 5px; color: #b0a7a2; font: 9px 'DM Sans'; letter-spacing: 1.2px; }
.profile-card { display: flex; align-items: center; gap: 10px; padding: 13px; margin-bottom: 28px; background: #fff5f0; border: 1px solid #f6e4dd; border-radius: 15px; }
.avatar { width: 35px; height: 35px; display: grid; place-items: center; flex: none; border-radius: 50%; background: var(--coral-soft); color: var(--coral-dark); font-weight: 700; }
.profile-copy { min-width: 0; }
.profile-name { overflow: hidden; max-width: 152px; color: var(--ink); font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.profile-role { margin-top: 2px; color: var(--muted); font-size: 11px; }
.online-dot { width: 8px; height: 8px; margin-left: auto; border-radius: 50%; background: #74bd8d; }
.nav { display: grid; gap: 6px; }
.nav-item { display: flex; align-items: center; width: 100%; border: 0; border-radius: 11px; padding: 12px 13px; background: transparent; color: var(--muted); text-align: left; font-size: 14px; }
.nav-item span { width: 31px; color: #c0b8b3; font: 600 10px 'DM Sans'; }
.nav-item.active { background: var(--coral-soft); color: var(--coral-dark); font-weight: 700; }
.nav-item.active span { color: var(--coral); }
.sidebar-note { display: flex; gap: 11px; margin: auto 9px 20px; padding-top: 28px; color: var(--muted); }
.ai-status { display: flex; gap: 10px; align-items: flex-start; margin: 0 8px 18px; padding: 12px; border: 1px solid #d4eadc; border-radius: 12px; background: var(--mint); color: var(--green); }
.ai-status strong { display: block; color: var(--ink); font-size: 12px; }
.ai-status p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.note-line { width: 3px; flex: none; border-radius: 4px; background: #efb07b; }
.sidebar-note strong { color: var(--ink); font-size: 13px; }
.sidebar-note p { margin: 5px 0 0; font-size: 12px; line-height: 1.65; }
.logout-button { border: 0; border-top: 1px solid var(--line); padding: 16px 8px 0; background: transparent; color: var(--muted); text-align: left; font-size: 13px; }
.sidebar-footer { margin: 18px 8px 0; color: #aaa19b; font-size: 11px; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #79bf90; }

.main-content { width: 100%; max-width: 1140px; margin: 0 auto; padding: 48px 68px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; }
.eyebrow { margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.topbar h1 { margin: 0; font-size: 34px; letter-spacing: -1px; line-height: 1.15; }
.subtitle { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.top-actions { display: flex; gap: 8px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); color: var(--muted); }

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 36px 0 28px; }
.stat-card { position: relative; min-height: 112px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); box-shadow: 0 5px 20px rgba(127, 87, 68, .035); }
.stat-card:nth-child(2) { background: var(--soft-green); border-color: #e4f0e5; }
.stat-card:nth-child(3) { background: var(--soft-yellow); border-color: #f4ead6; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 7px; font-size: 26px; font-weight: 700; line-height: 1; }
.stat-value small { color: var(--muted); font-size: 13px; font-weight: 400; }
.stat-index { position: absolute; top: 18px; right: 18px; color: #e2c1ba; font: 600 11px 'DM Sans'; }
.green-text { color: var(--green); }.orange-text { color: var(--orange); }
.stat-note { margin-top: 5px; color: #c88449; font-size: 12px; }

.workspace, .result-panel { max-height: 650px; overflow-y: auto; scrollbar-gutter: stable; border: 1px solid var(--line); border-radius: 18px; padding: 30px 32px; background: var(--white); box-shadow: var(--shadow); }
.workspace::-webkit-scrollbar, .result-panel::-webkit-scrollbar { width: 8px; }
.workspace::-webkit-scrollbar-thumb, .result-panel::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 8px; background: #eac2b9; background-clip: padding-box; }
.result-panel { margin-top: 18px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.section-heading h2 { margin: 0; font-size: 22px; line-height: 1.2; }.section-heading p:not(.section-kicker) { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.date-pill { padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field em { color: #b7ada8; font-style: normal; font-weight: 400; }
.field textarea { min-height: 150px; padding: 13px 14px; resize: vertical; font-size: 14px; line-height: 1.75; }.small-textarea { min-height: 110px !important; }
.field input { height: 46px; padding: 0 14px; font-size: 14px; }.field select { height: 46px; padding: 0 12px; font-size: 13px; }
.field-hint { display: block; margin-top: 6px; color: #b2a8a3; font-size: 12px; }
.full-field { margin-top: 18px; }
.preference-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 18px; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 26px; }.auto-save { color: var(--muted); font-size: 12px; }
.primary-button { min-width: 115px; }.primary-button span { margin-left: 12px; font-family: 'DM Sans'; font-size: 16px; }
.result-header { display: flex; align-items: flex-start; justify-content: space-between; }.result-header h2 { margin: 0; font-size: 20px; }.result-actions { display: flex; gap: 8px; }
.secondary-button { border: 1px solid var(--line); border-radius: 10px; padding: 9px 13px; background: var(--white); color: var(--muted); font-size: 13px; }
.secondary-button:hover { border-color: #e6b8ac; color: var(--coral-dark); }
.summary-box { min-height: 125px; margin-top: 21px; padding: 19px 21px; border-left: 4px solid var(--coral); border-radius: 0 12px 12px 0; background: var(--summary); color: #514946; font-size: 14px; line-height: 1.8; }.summary-box h3 { margin: 0 0 6px; color: var(--coral-dark); font-size: 15px; }.summary-box p { margin: 0 0 13px; }.summary-placeholder { padding: 19px; color: #b3aaa5; text-align: center; }.summary-placeholder small { font-size: 12px; }
.result-meta { display: flex; justify-content: space-between; margin-top: 13px; color: #aaa19b; font: 11px 'DM Sans'; }.result-meta span:first-child { color: var(--coral-dark); }
.history-view { display: none; }
.history-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: -6px 0 18px; flex-wrap: wrap; }
.history-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.history-filter { border: 1px solid var(--line); border-radius: 999px; padding: 7px 11px; background: var(--white); color: var(--muted); font-size: 12px; }
.history-filter.active { border-color: #f4d0c8; background: var(--coral-soft); color: var(--coral-dark); font-weight: 700; }
.history-toolbar select { height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; background: var(--white); color: var(--ink); font-size: 12px; }
.history-list { display: grid; gap: 11px; }
.history-item { padding: 20px 22px; border: 1px solid var(--line); border-radius: 15px; background: var(--white); }
.history-item-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-item time { color: var(--coral-dark); font-size: 13px; font-weight: 700; }
.history-item-actions { display: flex; align-items: center; gap: 10px; }
.history-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.history-tags span { border-radius: 999px; padding: 4px 8px; background: var(--paper); color: var(--muted); font-size: 11px; }
.history-copy, .history-edit, .history-delete, .history-cancel, .history-save { border: 0; border-radius: 8px; padding: 6px 9px; font-size: 12px; }
.history-copy, .history-edit, .history-cancel { background: var(--paper); color: var(--muted); }
.history-delete { background: #fff0ed; color: #c45f55; }
.history-save { background: var(--coral); color: #fff; }
.history-item p { max-width: 82ch; margin: 12px 0 0; color: var(--muted); font-size: 14px; line-height: 1.9; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.history-editor { margin-top: 14px; }
.history-editor textarea { width: 100%; min-height: 180px; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--input); color: var(--ink); font-size: 14px; line-height: 1.8; outline: none; }
.history-editor > div { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.summary-box.is-editing { border-color: var(--coral); outline: 3px solid var(--coral-soft); }
.history-empty { padding: 45px; color: var(--muted); text-align: center; }
.main-footer { margin-top: 32px; color: #b2a8a3; text-align: center; font-size: 11px; }.toast { position: fixed; right: 24px; bottom: 24px; z-index: 5; max-width: min(560px, calc(100vw - 48px)); padding: 13px 16px; border-radius: 11px; background: #3e3a39; color: white; font-size: 13px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s; }.toast.show { opacity: 1; transform: translateY(0); }

body.dark { --cream: #151918; --paper: #1c211f; --white: #232927; --ink: #f4f1ee; --muted: #b7b5ae; --line: #38413d; --coral: #ed8977; --coral-dark: #f0a092; --coral-soft: #3d2927; --mint: #1d352d; --green: #8bc6a3; --input: #1b211f; --soft-green: #203129; --soft-yellow: #332c20; --summary: #302624; --shadow: 0 14px 34px rgba(0, 0, 0, .2); }
.dark .auth-card, .dark .auth-field input, .dark .field input, .dark .field textarea, .dark .field select, .dark .icon-button, .dark .secondary-button { background: var(--white); color: var(--ink); }
.dark .sidebar, .dark .auth-screen { background: var(--paper); }
.dark .profile-card { background: #252c29; border-color: #35413c; }
.dark .stat-card:nth-child(2) { border-color: #35503f; }
.dark .stat-card:nth-child(3) { border-color: #574932; }
.dark .summary-box { background: var(--summary); color: #f1e5df; }
.dark .history-tags span, .dark .history-copy, .dark .history-edit, .dark .history-cancel { background: #303734; }
.dark .history-delete { background: #432c2b; color: #f0a092; }
.dark .history-editor textarea { background: #1b211f; }
.dark .ai-status { border-color: #355344; }
@media (max-width: 880px) { .sidebar { width: 220px; }.main-content { padding: 38px 28px; } }
@media (max-width: 660px) { .auth-card { padding: 30px 23px; }.app-shell { display: block; }.sidebar { display: block; width: 100%; padding: 18px; }.brand { margin-bottom: 18px; }.profile-card,.sidebar-note,.ai-status,.sidebar-footer,.logout-button { display: none; }.nav { display: flex; }.nav-item { flex: 1; }.main-content { padding: 27px 16px; }.topbar h1 { font-size: 28px; }.stats-row,.form-grid,.preference-row { grid-template-columns: 1fr; }.stats-row { gap: 9px; margin: 25px 0; }.workspace,.result-panel { max-height: none; overflow: visible; padding: 22px 18px; }.result-header { display: block; }.result-actions { margin-top: 14px; }.form-footer { align-items: flex-end; }.section-heading { gap: 10px; }.date-pill { white-space: nowrap; }.history-toolbar { align-items: stretch; }.history-toolbar select { width: 100%; }.history-item-top { align-items: flex-start; flex-direction: column; }.history-tags { justify-content: flex-start; } }
