@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Noto+Sans+Thai:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #6366f1;
  --bg: #eff6ff;
  --card-bg: rgba(255, 255, 255, 0.65);
  --card-border: rgba(255, 255, 255, 0.8);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-light: rgba(15, 23, 42, 0.1);
  --shadow-soft: 0 12px 40px rgba(37, 99, 235, 0.08);
  --shadow-hover: 0 16px 50px rgba(99, 102, 241, 0.15);
  --radius-lg: 24px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text-main);
  font-family: 'Outfit', 'Noto Sans Thai', sans-serif;
  overflow-x: hidden;
  position: relative;
}

/* Animated Background Shapes */
.bg-shapes {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  overflow: hidden;
}

.shape {
  position: absolute;
  filter: blur(100px);
  opacity: 0.6;
  border-radius: 50%;
  animation: float 20s infinite ease-in-out alternate;
}

.shape-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99,102,241,0.4) 0%, rgba(37,99,235,0) 70%);
  top: -100px;
  left: -150px;
  animation-delay: 0s;
}

.shape-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(56,189,248,0.4) 0%, rgba(14,165,233,0) 70%);
  bottom: -50px;
  right: -100px;
  animation-delay: -5s;
}

.shape-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(168,85,247,0.3) 0%, rgba(147,51,234,0) 70%);
  top: 40%;
  left: 30%;
  animation-delay: -10s;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(50px, -50px) scale(1.1); }
}

.shell {
  width: min(1100px, calc(100% - 32px));
  margin: 40px auto 60px;
  position: relative;
  z-index: 1;
}

.brand {
  text-align: center;
  margin-bottom: 2rem;
}

.brand h1 {
  margin: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-weight: 500;
}

.stack {
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px 32px;
  box-shadow: var(--shadow-soft);
  transition: var(--transition);
}

.panel:hover {
  box-shadow: var(--shadow-hover);
  border-color: rgba(255, 255, 255, 0.9);
}

.hidden {
  display: none !important;
}

.form {
  display: grid;
  gap: 16px;
}

label {
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: -4px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.7);
  padding: 0 16px;
  font-size: 1rem;
  color: var(--text-main);
  font-family: inherit;
  transition: var(--transition);
}

textarea {
  padding: 14px 16px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

button {
  min-height: 48px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #ffffff;
  font-weight: 600;
  font-size: 1rem;
  padding: 0 20px;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.5);
  color: var(--primary);
  border: 1px solid var(--border-light);
  box-shadow: none;
}

.ghost-btn:hover {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.secondary-btn {
  background: linear-gradient(135deg, #475569, #334155);
  box-shadow: 0 4px 12px rgba(71, 85, 105, 0.2);
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 20px;
}

.status-card {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: var(--transition);
}

.status-card:hover {
  transform: scale(1.02);
  background: #ffffff;
}

.status-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-value {
  margin: 8px 0 0;
  color: var(--primary);
  font-weight: 700;
  font-size: 1.1rem;
  word-break: break-word;
}

.endpoint {
  font-size: 0.85rem;
  font-weight: 500;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

/* Segmented Tabs */
.segmented-wrap {
  padding: 8px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
}

.segmented {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.05);
  border-radius: 100px;
  padding: 6px;
  gap: 4px;
}

.seg-btn {
  background: transparent;
  color: var(--text-muted);
  border-radius: 100px;
  min-height: 40px;
  box-shadow: none;
  font-weight: 500;
  padding: 0 24px;
}

.seg-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.5);
  transform: none;
  box-shadow: none;
}

.seg-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

/* Panel Titles */
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.panel-title-row h2,
.panel-title-row h3 {
  margin: 0;
  color: var(--text-main);
  font-weight: 700;
}

.panel-title-row h2 { font-size: 1.3rem; }
.panel-title-row h3 { font-size: 1.1rem; }

/* Tables */
.table-wrap {
  margin-top: 16px;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.6);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.95rem;
}

th, td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  vertical-align: middle;
}

th {
  background: rgba(255, 255, 255, 0.8);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: var(--transition);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* Form Specifics */
.customer-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.customer-form input:first-child,
.customer-form textarea,
.customer-actions { grid-column: 1 / -1; }
.customer-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.quotation-form { gap: 16px; }
.item-actions { margin-top: 12px; margin-bottom: 4px; }
.inline-actions { display: flex; gap: 12px; }

.totals {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.8);
  margin-top: 16px;
  text-align: right;
}

.totals p {
  margin: 8px 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.totals strong {
  color: var(--text-main);
  font-size: 1.1rem;
  display: inline-block;
  width: 120px;
}

#grand-total-view {
  color: var(--primary);
  font-size: 1.3rem;
}

.quotation-actions { grid-template-columns: 1fr; }

.payment-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.payment-form textarea,
.payment-actions { grid-column: 1 / -1; }
.payment-actions { grid-template-columns: 1fr; }

.settings-form { gap: 16px; }
.settings-actions { grid-template-columns: 1fr; }

/* Utilities */
.items-table input { min-height: 40px; }
.items-table .number-input { min-width: 120px; text-align: right; }
.money-cell { min-width: 120px; text-align: right; font-weight: 600; color: var(--primary); }
.doc-actions { min-width: 190px; white-space: nowrap; }
.doc-actions button + button { margin-left: 8px; }
.empty-cell { text-align: center !important; color: var(--text-muted); font-style: italic; }

.status {
  margin: 16px 4px 0;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 500;
}

.log-view {
  margin: 0;
  min-height: 200px;
  max-height: 300px;
  overflow-y: auto;
  border-radius: var(--radius-md);
  padding: 16px;
  background: #1e293b;
  color: #f8fafc;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.5); }

/* Quick Actions CTA */
.quick-actions-row {
  display: flex;
  justify-content: center;
  margin: 10px 0 20px 0;
}

.cta-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  font-size: 1.15rem;
  padding: 0 40px;
  min-height: 54px;
  border-radius: 100px;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
  letter-spacing: 0.5px;
}

.cta-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 32px rgba(16, 185, 129, 0.4);
}

/* Responsive */
@media (max-width: 860px) {
  .cards { grid-template-columns: 1fr; }
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-form { grid-template-columns: 1fr; }
  .payment-form { grid-template-columns: 1fr; }
  .panel { padding: 20px; }
}

@media (max-width: 620px) {
  .segmented {
    width: 100%;
    flex-direction: column;
    border-radius: var(--radius-md);
  }
  .seg-btn { width: 100%; border-radius: var(--radius-sm); }
  .inline-actions { width: 100%; flex-direction: column; }
  .inline-actions button { width: 100%; }
}

@media (max-width: 520px) {
  .shell { width: calc(100% - 24px); margin-top: 24px; }
  .panel { padding: 16px; }
  .actions { grid-template-columns: 1fr; }
}
