:root {
  --primary-900: #2C3E50;
  --primary-800: #34495E;
  --primary-600: #5D6D7E;
  --bg: #F5F6F7;
  --card: #FFFFFF;
  --line: #E5E7EB;
  --text: #1F2937;
  --muted: #6B7280;
  --disabled: #9CA3AF;
  --accent-beige: #D9C7A7;
  --accent-brown: #8C5A3C;
  --accent-olive: #6E7051;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;
  --neutral: #9CA3AF;
  --primary: var(--primary-900);
  --page-padding: 16px;
  --block-gap: 16px;
  --gap-sm: 8px;
  --radius-card: 8px;
  --radius-input: 6px;
  --radius-btn: 6px;
  --font-main: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.ai-chat-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  pointer-events: none;
}
.ai-chat-fab {
  pointer-events: auto;
  min-width: 104px;
  height: 44px;
  border: 1px solid rgba(44, 62, 80, 0.2);
  border-radius: 999px;
  background: linear-gradient(135deg, #203246 0%, #6e7051 100%);
  color: #fff;
  box-shadow: 0 16px 40px rgba(31, 41, 55, 0.24);
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
}
.ai-chat-panel {
  pointer-events: auto;
  position: absolute;
  right: 0;
  bottom: 56px;
  width: min(420px, calc(100vw - 28px));
  height: min(640px, calc(100vh - 96px));
  display: none;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  border: 1px solid rgba(44, 62, 80, 0.16);
  border-radius: 22px;
  background: #fbfaf6;
  box-shadow: 0 24px 70px rgba(31, 41, 55, 0.28);
}
.ai-chat-widget.open .ai-chat-panel {
  display: grid;
}
.ai-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  background: linear-gradient(135deg, #f7efe1 0%, #eef3ed 100%);
  border-bottom: 1px solid rgba(44, 62, 80, 0.1);
}
.ai-chat-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  color: var(--primary-900);
}
.ai-chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.ai-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.65);
  font-size: 22px;
}
.ai-chat-quota {
  padding: 8px 18px;
  border-bottom: 1px solid rgba(44, 62, 80, 0.08);
  color: var(--muted);
  font-size: 12px;
  background: #fffdf8;
}
.ai-chat-messages {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: grid;
  align-content: start;
  gap: 12px;
}
.ai-chat-message {
  display: grid;
  gap: 4px;
}
.ai-chat-message.user {
  justify-items: end;
}
.ai-chat-message__meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ai-chat-message__bubble {
  max-width: 92%;
  padding: 11px 13px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid rgba(44, 62, 80, 0.1);
  color: var(--text);
  box-shadow: 0 8px 22px rgba(31, 41, 55, 0.06);
}
.ai-chat-message.user .ai-chat-message__bubble {
  background: #203246;
  color: #fff;
  border-color: #203246;
  border-bottom-right-radius: 5px;
}
.ai-chat-message.assistant .ai-chat-message__bubble {
  border-bottom-left-radius: 5px;
}
.ai-chat-form {
  padding: 12px;
  border-top: 1px solid rgba(44, 62, 80, 0.1);
  background: #fff;
}
.ai-chat-input {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  outline: none;
}
.ai-chat-input:focus {
  border-color: var(--primary-900);
  box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.08);
}
.ai-chat-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}
.ai-chat-note {
  color: var(--muted);
  font-size: 12px;
}
@media (max-width: 640px) {
  .ai-chat-widget {
    right: 12px;
    bottom: 12px;
  }
  .ai-chat-panel {
    right: -2px;
    width: calc(100vw - 20px);
    height: min(620px, calc(100vh - 86px));
  }
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 24px;
}
.login-title {
  margin: 0 0 18px;
  font-size: 20px;
  line-height: 1.2;
  color: var(--text);
}
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.input, .select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 0 10px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.input:focus, .select:focus {
  border-color: var(--primary-900);
  box-shadow: 0 0 0 2px rgba(44, 62, 80, 0.08);
}
.btn {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-btn);
  padding: 8px 16px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn.primary {
  background: var(--primary-900);
  color: #fff;
  border-color: var(--primary-900);
}
.btn.primary:hover { background: var(--primary-800); border-color: var(--primary-800); }
.btn:hover { background: #F9FAFB; }
.btn:disabled,
.icon-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.status {
  min-height: 20px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
  color: var(--muted);
}
.status.error { color: var(--danger); }
.status.success { color: var(--success); }
.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}
.workspace-toolbar__meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.workspace-toolbar__label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.workspace-toolbar__hint {
  color: var(--muted);
  font-size: 12px;
}
.workspace-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  background: #f4f7fb;
  border: 1px solid var(--line);
  border-radius: 999px;
  flex: 0 0 auto;
}
.workspace-mode__btn {
  min-width: 82px;
  height: 34px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.workspace-mode__btn.active {
  background: var(--primary-900);
  color: #fff;
}
.workspace-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}
.workspace-tabs-bar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.workspace-tab {
  min-width: 210px;
  max-width: 280px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.workspace-tab.active {
  border-color: rgba(44, 62, 80, 0.25);
  box-shadow: inset 0 0 0 1px rgba(44, 62, 80, 0.08);
  background: #eef4fb;
}
.workspace-tab__dirty {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #d8dde6;
  flex: 0 0 auto;
}
.workspace-tab.dirty .workspace-tab__dirty {
  background: var(--warning);
}
.workspace-tab__meta {
  min-width: 0;
  flex: 1;
}
.workspace-tab__title,
.workspace-tab__sub {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-tab__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.workspace-tab__sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}
.workspace-tab__close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.workspace-tab__close:hover {
  background: rgba(44, 62, 80, 0.08);
  color: var(--text);
}
.workspace-panels {
  position: relative;
  min-height: 70vh;
}
.workspace-panel {
  display: none;
  height: 100%;
}
.workspace-panel.active {
  display: block;
}
.workspace-frame {
  width: 100%;
  min-height: 70vh;
  height: 70vh;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}
.workspace-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  font-size: 14px;
  background: #fff;
}
.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  transition: grid-template-columns 0.24s ease;
}
.embedded-shell {
  min-height: 100vh;
  background: var(--bg);
}
.embedded-content {
  max-width: none;
  padding: 16px;
}
.layout.collapsed {
  grid-template-columns: 60px 1fr;
}
.sidebar {
  background: var(--primary-900);
  color: #dbe8f5;
  padding: 16px 12px;
  border-right: 1px solid rgba(255,255,255,0.08);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transition: padding 0.24s ease;
}
.sidebar-main {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
}
.sidebar-nav {
  overflow: visible;
  padding-right: 2px;
}
.sidebar-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.12);
  flex: 0 0 auto;
}
.sidebar-action-btn {
  margin-bottom: 0;
  justify-content: center;
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
}
.sidebar-action-btn:hover {
  background: rgba(255,255,255,0.12);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  padding: 8px 8px 16px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: #f3f8ff;
  flex: 0 0 auto;
}
.brand-mark svg,
.side-btn .icon svg {
  width: 20px;
  height: 20px;
  display: block;
}
.layout.collapsed .brand {
  justify-content: center;
  padding: 8px 0 16px;
}
.layout.collapsed .brand-text {
  display: none;
}
.nav-group {
  margin-bottom: 8px;
}
.nav-group.active-group .nav-group-btn {
  background: rgba(255,255,255,0.08);
  box-shadow: inset 3px 0 0 var(--accent-beige);
}
.side-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: none;
  background: transparent;
  color: #dbe8f5;
  border-radius: 8px;
  padding: 10px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-weight: 600;
}
.side-btn .icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #dbe8f5;
  flex: 0 0 auto;
}
.side-btn.active, .side-btn:hover {
  background: rgba(255,255,255,0.08);
}
.toggle-btn {
  margin-bottom: 12px;
}
.layout.collapsed .toggle-btn {
  justify-content: center;
  padding: 10px 0;
}
.nav-group-btn {
  position: relative;
}
.nav-group-btn .chevron {
  margin-left: auto;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: transform 0.15s ease;
}
.nav-group-btn .chevron svg {
  width: 16px;
  height: 16px;
}
.nav-group.expanded .nav-group-btn .chevron {
  transform: rotate(180deg);
}
.submenu {
  display: none;
  margin: 4px 0 10px;
  padding: 0 0 0 18px;
}
.nav-group.expanded .submenu {
  display: grid;
  gap: 6px;
}
.submenu-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.02);
  color: #dbe8f5;
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}
.submenu-btn:hover {
  background: rgba(255,255,255,0.08);
}
.submenu-btn.active {
  background: rgba(217, 199, 167, 0.18);
  border-color: rgba(217, 199, 167, 0.42);
  color: #ffffff;
}
.submenu-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.submenu-btn.placeholder {
  color: #dbe8f5;
}
.layout.collapsed .side-btn {
  justify-content: center;
  padding: 10px 0;
}
.layout.collapsed .side-btn .text,
.layout.collapsed .side-btn .chevron,
.layout.collapsed .submenu {
  display: none;
}
.layout.collapsed .sidebar {
  padding: 16px 8px;
}
.layout.collapsed .sidebar-footer {
  grid-template-columns: 1fr;
}
.submenu-tag {
  display: none !important;
}
main {
  min-width: 0;
}
.content {
  padding: var(--page-padding);
}
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 16px;
  margin-bottom: var(--block-gap);
}
.placeholder-card {
  border-style: dashed;
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
}
.title {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.sub {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  overflow: auto;
}
.erp-compact-table tbody tr {
  height: 46px;
}
.erp-compact-table td {
  vertical-align: middle;
  white-space: nowrap;
}
.ellipsis-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-note {
  max-width: 220px;
}
.text-btn {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.order-output-summary {
  width: 100%;
  font-weight: 700;
}
.erp-action-trigger {
  width: 40px;
  height: 40px;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  justify-content: center;
}
.overlay-menu-box {
  position: fixed;
  z-index: 10010;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(31, 41, 55, 0.12);
  overflow: hidden;
}
.overlay-menu-item {
  width: 100%;
  border: none;
  background: #fff;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}
.overlay-menu-item:hover {
  background: #F3F4F6;
}
.overlay-menu-item.danger {
  color: var(--danger);
}
.overlay-menu-item.danger:hover {
  background: #fff1ef;
}
.overlay-output-box {
  padding: 10px 0;
}
.overlay-menu-title {
  padding: 0 12px 8px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
}
.overlay-output-item {
  display: grid;
  gap: 4px;
  padding: 8px 12px;
}
.overlay-output-item span {
  color: var(--muted);
  font-size: 12px;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}
th {
  background: var(--primary-900);
  color: #fff;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 8px;
  white-space: nowrap;
}
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  font-size: 14px;
  white-space: nowrap;
}
.table-wrap tbody tr:hover td {
  background: #F3F4F6;
}
.toolbar {
  display: flex;
  gap: var(--gap-sm);
  flex-wrap: wrap;
  align-items: end;
}
.grid {
  display: grid;
  gap: var(--gap-sm);
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}
.row {
  display: flex;
  gap: var(--gap-sm);
  flex-wrap: wrap;
}
.autocomplete-wrap {
  position: relative;
}
.suggest-box {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(31, 41, 55, 0.12);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}
.suggest-item {
  width: 100%;
  border: none;
  background: #fff;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 4px;
}
.suggest-item:hover,
.suggest-item.active {
  background: #F3F4F6;
}
.suggest-item span,
.suggest-empty {
  color: var(--muted);
  font-size: 12px;
}
.suggest-empty {
  padding: 12px;
}
.negative-value {
  color: var(--danger) !important;
  font-weight: 800;
}
.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 108px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
  background: #f5f5f5;
}
.status-chip.active,
.status-chip.in_progress { color: #0F766E; background: rgba(16,185,129,0.12); border-color: rgba(16,185,129,0.2); }
.status-chip.partial { color: #0F766E; background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.2); }
.status-chip.completed { color: #047857; background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.24); }
.status-chip.pending { color: #6B7280; background: rgba(156,163,175,0.16); border-color: rgba(156,163,175,0.24); }
.status-chip.waiting_material,
.status-chip.draft { color: #6B7280; background: rgba(156,163,175,0.16); border-color: rgba(156,163,175,0.24); }
.status-chip.pending_approval { color: #92400E; background: rgba(245,158,11,0.16); border-color: rgba(245,158,11,0.26); }
.status-chip.stopped,
.status-chip.inactive { color: #B91C1C; background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.24); }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 18, 33, 0.42);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-shell {
  width: min(760px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  background: #fff;
  border-radius: var(--radius-card);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 48px rgba(31, 41, 55, 0.18);
}
.modal-wide {
  width: min(1180px, calc(100vw - 36px));
}
.payment-depreciation-modal-shell {
  width: min(720px, calc(100vw - 36px));
}
.payment-depreciation-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}
.payment-depreciation-hint {
  margin-top: 14px;
}
.modal-production {
  width: min(90vw, 1600px);
  height: min(90vh, 980px);
  max-height: min(90vh, 980px);
}
.modal-header,
.modal-footer {
  padding: 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 2;
}
.sticky-bottom {
  position: sticky;
  bottom: 0;
  z-index: 2;
}
.modal-body {
  padding: 16px;
  overflow: auto;
}
.section-card {
  padding: 16px;
  margin-top: 16px;
}
.nested-card {
  background: #FAFAFA;
  border: 1px solid var(--line);
}
.section-title,
.section-subtitle {
  margin: 0;
  color: var(--text);
  font-weight: 600;
}
.section-subtitle {
  font-size: 16px;
}
.compact-summary {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}
.row-selected td {
  background: #f0f7ff;
}
.overlay-suggest-box {
  position: fixed;
  z-index: 9999;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(31, 41, 55, 0.16);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary-900);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover {
  background: #F9FAFB;
}
.payment-type-active-depreciation {
  color: #b91c1c;
  font-weight: 700;
}
.payment-type-ended-depreciation {
  color: #15803d;
  font-weight: 700;
}
.summary-strip {
  display: grid;
  gap: var(--gap-sm);
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}
.right { text-align: right; }
.hidden { display: none !important; }
iframe.module-frame {
  width: 100%;
  height: 360px;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  display: block;
  overflow: auto;
}
@media (max-width: 900px) {
  .layout, .layout.collapsed { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid { grid-template-columns: 1fr; }
  .payment-depreciation-grid { grid-template-columns: 1fr; }
  .summary-strip { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 10px; }
}
