:root {
  --primary: #0078D4;
  --primary-light: #106EBE;
  --primary-dark: #005A9E;
  --accent: #2B88D8;
  --accent-hover: #106EBE;
  --sidebar-width: 260px;
  --bg-light: #F5F5F5;
  --success: #107C10;
  --danger: #D13438;
  --warning: #FFB900;
  --info: #0078D4;
  --text-primary: #323130;
  --text-secondary: #605E5C;
  --border-color: #EDEBE9;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  margin: 0;
  background: var(--bg-light);
  color: var(--text-primary);
}

/* LOGIN PAGE */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.login-card h1 {
  color: var(--primary);
  margin-bottom: 8px;
  font-size: 28px;
}

.login-card .subtitle {
  color: #888;
  margin-bottom: 30px;
  font-size: 14px;
}

.login-card .logo-icon {
  font-size: 48px;
  text-align: center;
  margin-bottom: 20px;
  color: var(--primary);
}

/* SIDEBAR */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--primary);
  color: white;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.sidebar-header .app-subtitle {
  font-size: 11px;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.sidebar-nav {
  padding: 10px 0;
}

.sidebar-section {
  padding: 10px 20px 5px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.5;
  margin-top: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  color: rgba(255,255,255,0.8);
  width: 100%;
  text-align: left;
  font-size: 14px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.nav-item.active {
  background: rgba(255,255,255,0.15);
  color: white;
  border-right: 3px solid #fff;
}

.nav-item i {
  width: 24px;
  margin-right: 12px;
  text-align: center;
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.1);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-role {
  font-size: 11px;
  opacity: 0.6;
  text-transform: capitalize;
}

/* MAIN CONTENT */
.main-content {
  margin-left: var(--sidebar-width);
  padding: 24px;
  min-height: 100vh;
}

/* TOP BAR */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.top-bar h1 {
  font-size: 24px;
  margin: 0;
  color: var(--primary);
}

.search-box {
  position: relative;
}

.search-box input {
  padding: 8px 16px 8px 36px;
  border: 1px solid #ddd;
  border-radius: 8px;
  width: 300px;
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,120,212,0.15);
}

.search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #aaa;
}

/* CARDS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow 0.2s;
}

.stat-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
}

.stat-icon.blue { background: var(--info); }
.stat-icon.green { background: var(--success); }
.stat-icon.orange { background: var(--warning); }
.stat-icon.red { background: var(--danger); }
.stat-icon.purple { background: #8e44ad; }

.stat-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* PANEL / TABLE */
.panel {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  margin-bottom: 24px;
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.panel:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.panel-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--primary);
}

.panel-body {
  padding: 20px;
}

.panel-body.no-padding {
  padding: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #FAFAFA;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tr:hover td {
  background: #f8f9fb;
}

.data-table .actions {
  white-space: nowrap;
}

.table-wrapper {
  overflow-x: auto;
  max-height: 600px;
  overflow-y: auto;
}

/* BUTTONS */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-light); }

.btn-accent {
  background: var(--accent);
  color: white;
}

.btn-accent:hover { background: var(--accent-hover); }

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover { background: #c0392b; }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-outline {
  background: transparent;
  border: 1px solid #ddd;
  color: #555;
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: #DFF6DD; color: #107C10; }
.badge-blue { background: #DEECF9; color: #0078D4; }
.badge-orange { background: #FFF4CE; color: #8A7400; }
.badge-red { background: #FDE7E9; color: #D13438; }
.badge-purple { background: #E8DAEF; color: #5C2D91; }
.badge-gray { background: var(--border-color); color: var(--text-secondary); }

/* FORMS */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin-bottom: 4px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,120,212,0.15);
}

select.form-control {
  appearance: auto;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  margin: 0;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 0;
  line-height: 1;
}

.modal-close:hover { color: #333; }

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* TABS */
.tabs {
  display: flex;
  border-bottom: 2px solid #eee;
  margin-bottom: 20px;
}

.tab {
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  color: #888;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab:hover {
  color: var(--primary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ENTITY DETAIL */
.entity-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.entity-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
}

.entity-title h2 {
  margin: 0;
  font-size: 22px;
  color: var(--primary);
}

.entity-title .entity-code {
  font-size: 13px;
  color: #888;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.detail-item {
  padding: 10px;
  background: #f8f9fa;
  border-radius: 6px;
}

.detail-item .label {
  font-size: 11px;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 0.5px;
}

.detail-item .value {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-top: 2px;
}

/* CHARTS AREA */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-bar-label {
  width: 120px;
  font-size: 12px;
  text-align: right;
  color: #666;
  flex-shrink: 0;
}

.chart-bar-track {
  flex: 1;
  height: 24px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-size: 11px;
  color: white;
  font-weight: 600;
  min-width: 30px;
  transition: width 0.5s;
}

/* TOAST */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
}

.toast {
  background: white;
  border-radius: 8px;
  padding: 12px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  animation: slideIn 0.3s ease;
  border-left: 4px solid var(--success);
}

.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* IMPORT */
.import-zone {
  border: 2px dashed #ccc;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

.import-zone:hover {
  border-color: var(--primary);
}

.import-zone i {
  font-size: 48px;
  color: #ccc;
  margin-bottom: 12px;
}

.import-zone p {
  color: #888;
  margin: 0;
}

.hidden { display: none !important; }

/* ============ AI CHAT ============ */
.ai-chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,120,212,0.35);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.ai-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0,120,212,0.45);
}

.ai-chat-fab.active {
  background: var(--danger);
  box-shadow: 0 4px 16px rgba(209,52,56,0.35);
}

.ai-chat-fab.active i::before {
  content: "\f00d";
}

.ai-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  width: 380px;
  height: 520px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  z-index: 150;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: aiSlideUp 0.3s ease;
}

.ai-chat-panel.active {
  display: flex;
}

@keyframes aiSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-header {
  background: var(--primary);
  color: white;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.ai-chat-name {
  font-weight: 600;
  font-size: 15px;
}

.ai-chat-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #57E389;
  display: inline-block;
}

.ai-chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  opacity: 0.8;
  line-height: 1;
  padding: 0;
}

.ai-chat-close:hover { opacity: 1; }

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #F5F5F5;
}

.ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}

.ai-msg.bot {
  background: white;
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.ai-msg.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-typing {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  align-self: flex-start;
}

.ai-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #B0B0B0;
  animation: aiDot 1.2s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.ai-chat-input-area {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  background: white;
}

.ai-chat-input {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 13px;
  outline: none;
  transition: border 0.2s;
}

.ai-chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,120,212,0.1);
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.ai-chat-send:hover {
  background: var(--primary-dark);
}

/* Entity edit mode */
.entity-edit-mode {
  background: #FFF8E1;
  border: 1px solid #FFD54F;
  border-radius: 8px;
  padding: 16px;
}

.entity-edit-mode .detail-item {
  background: white;
  border: 1px solid #E0E0E0;
}

.entity-edit-mode .form-control {
  margin-top: 4px;
}

/* Sub-table action buttons */
.data-table .actions .btn {
  margin-right: 4px;
}

.data-table .actions .btn:last-child {
  margin-right: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
}
