/* Haeil ERP — shared component styles (works with Tailwind utilities) */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: #f8fafc;
  color: #0f172a;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ——— Form controls ——— */
.label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  margin-bottom: 0.375rem;
}

.input {
  display: block;
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: #0f172a;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.input:disabled {
  background: #f1f5f9;
  color: #94a3b8;
  cursor: not-allowed;
}
textarea.input {
  resize: vertical;
  min-height: 2.5rem;
}
select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
  padding-right: 2.5rem;
}

.form-group {
  margin-bottom: 1.25rem;
}
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  margin-bottom: 0.375rem;
}
.form-input {
  display: block;
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: #0f172a;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.icon-input {
  position: relative;
}
.icon-input i {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.875rem;
  pointer-events: none;
}
.icon-input .form-input,
.icon-input .input {
  padding-left: 2.5rem;
}
.icon-input .toggle-btn {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.25rem;
}
.icon-input .toggle-btn:hover {
  color: #475569;
}

/* ——— Buttons ——— */
.btn,
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.25;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}
.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.btn-secondary {
  background: #fff;
  color: #334155;
  border-color: #e2e8f0;
}
.btn-secondary:hover:not(:disabled) {
  background: #f8fafc;
  color: #0f172a;
}
.btn-secondary.active {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}
.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* ——— Cards ——— */
.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
  margin: 0;
}
.card-body {
  padding: 1.5rem;
}

/* ——— Tables ——— */
.table-wrap, .overflow-x-auto {
  overflow-x: auto;
}
.table, .data-table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .data-table th {
  padding: 0.75rem 1.5rem;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.table td, .data-table td {
  padding: 0.875rem 1.5rem;
  font-size: 0.8125rem;
  color: #334155;
  border-bottom: 1px solid #f1f5f9;
}
.table tbody tr:hover td, .data-table tbody tr:hover td {
  background: #f8fafc;
}

/* ——— Badges ——— */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 9999px;
  line-height: 1.25;
}
.badge-green {
  background: #dcfce7;
  color: #166534;
}
.badge-yellow {
  background: #fef9c3;
  color: #854d0e;
}
.badge-red {
  background: #fee2e2;
  color: #991b1b;
}
.badge-blue {
  background: #dbeafe;
  color: #1e40af;
}
.badge-gray {
  background: #f1f5f9;
  color: #475569;
}
.badge-purple {
  background: #f3e8ff;
  color: #6b21a8;
}
.badge-orange {
  background: #ffedd5;
  color: #9a3412;
}
.badge-indigo {
  background: #e0e7ff;
  color: #3730a3;
}
.badge-teal {
  background: #ccfbf1;
  color: #0f766e;
}

/* ——— Stats ——— */
.stat-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

/* ——— Alerts ——— */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}
.alert-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

/* ——— Modal ——— */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-overlay.show {
  display: flex;
}
.modal-box {
  background: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 32rem;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #0f172a;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.25rem;
}
.modal-close:hover {
  color: #475569;
}
.modal-body {
  padding: 1.5rem;
}
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ——— Tabs ——— */
.tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: 0.75rem 1.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #64748b;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover {
  color: #334155;
}
.tab-btn.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
}

/* ——— Auth / login ——— */
.login-card {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  padding: 2.5rem;
  width: 100%;
  max-width: 28rem;
}
.logo-box {
  width: 4rem;
  height: 4rem;
  background: #2563eb;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}
.logo-box i {
  color: #fff;
  font-size: 1.75rem;
}

/* ——— Error pages ——— */
.error-code {
  font-size: 6rem;
  font-weight: 700;
  color: #e2e8f0;
  line-height: 1;
}
.error-icon {
  width: 5rem;
  height: 5rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
}

/* ——— App shell (sidebar / topbar) ——— */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 16rem;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.2s;
}
.sidebar-logo {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-logo-box {
  width: 2.5rem;
  height: 2.5rem;
  background: #2563eb;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo-box i {
  color: #fff;
  font-size: 1.125rem;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}
.sidebar-section {
  padding: 0.75rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #475569;
  border-radius: 0.5rem;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
  margin-bottom: 0.125rem;
}
.sidebar-link:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.sidebar-link.active {
  background: #eff6ff;
  color: #2563eb;
}
.sidebar-link i {
  width: 1.25rem;
  text-align: center;
  font-size: 0.875rem;
}
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid #e2e8f0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-avatar {
  width: 2.25rem;
  height: 2.25rem;
  background: #dbeafe;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-avatar span {
  color: #2563eb;
  font-size: 0.875rem;
  font-weight: 600;
}

.main-area {
  flex: 1;
  margin-left: 16rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-search {
  position: relative;
}
.topbar-search input {
  width: 24rem;
  max-width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-size: 0.8125rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  background: #f8fafc;
}
.topbar-search input:focus {
  outline: none;
  border-color: #3b82f6;
  background: #fff;
}
.topbar-search i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.8125rem;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.topbar-btn {
  position: relative;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.topbar-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.topbar-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 0.875rem;
  height: 0.875rem;
  background: #ef4444;
  color: #fff;
  font-size: 0.625rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.company-select {
  font-size: 0.8125rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  background: #fff;
  color: #334155;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
}
.user-menu-btn:hover {
  background: #f1f5f9;
}
.user-avatar-sm {
  width: 2rem;
  height: 2rem;
  background: #dbeafe;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-avatar-sm span {
  color: #2563eb;
  font-size: 0.75rem;
  font-weight: 600;
}

.page-content {
  flex: 1;
  padding: 1.5rem;
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-area {
    margin-left: 0;
  }
  .topbar-search input {
    width: 16rem;
  }
}

@media (max-width: 640px) {
  .topbar-search {
    display: none;
  }
  .page-content {
    padding: 1rem;
  }
}

/* ——— Dashboard-style UI (soft tinted tiles, quick actions) ——— */
body { background: #f4f7fb; }
.card { border-radius: 1rem; border-color: #e8edf4; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
.card-header { background: #fff; }
.page-title { font-size: 1.625rem; font-weight: 700; color: #0f172a; margin: 0; }
.page-sub { font-size: 0.8125rem; color: #64748b; margin: 0.125rem 0 1.25rem; }

.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.tile {
  --tint: #3b82f6; --tint-bg: #eff6ff;
  display: flex; align-items: center; gap: 0.875rem;
  padding: 1rem 1.125rem; border-radius: 1rem; text-decoration: none;
  background: linear-gradient(135deg, var(--tint-bg) 0%, #fff 85%);
  border: 1px solid rgba(15, 23, 42, 0.05);
  box-shadow: 0 4px 14px -8px rgba(15, 23, 42, 0.18);
  transition: transform 0.15s, box-shadow 0.15s;
}
a.tile:hover { transform: translateY(-2px); box-shadow: 0 10px 20px -10px rgba(15, 23, 42, 0.25); }
.tile-icon {
  width: 2.75rem; height: 2.75rem; border-radius: 0.75rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--tint); color: #fff; font-size: 1.0625rem;
}
.tile-label { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: #64748b; }
.tile-value { font-size: 1.1875rem; font-weight: 700; color: #0f172a; line-height: 1.25; }
.tile-note { font-size: 0.6875rem; color: #94a3b8; }
.tile-blue   { --tint: #3b82f6; --tint-bg: #e8f1ff; }
.tile-green  { --tint: #10b981; --tint-bg: #e6f9f1; }
.tile-amber  { --tint: #f59e0b; --tint-bg: #fff4e0; }
.tile-red    { --tint: #ef4444; --tint-bg: #ffecec; }
.tile-purple { --tint: #8b5cf6; --tint-bg: #f1ebff; }
.tile-teal   { --tint: #14b8a6; --tint-bg: #e3f8f6; }
.tile-indigo { --tint: #6366f1; --tint-bg: #ececff; }
.tile-yellow { --tint: #eab308; --tint-bg: #fef9dc; }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }
.quick-action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 1.125rem 0.75rem; border-radius: 0.875rem; color: #fff; text-decoration: none;
  font-size: 0.8125rem; font-weight: 600; text-align: center; border: 0; cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
}
.quick-action i { font-size: 1.25rem; }
.quick-action:hover { transform: translateY(-2px); filter: brightness(1.06); color: #fff; }
.qa-blue { background: #2563eb; } .qa-green { background: #059669; } .qa-sky { background: #0ea5e9; }
.qa-red { background: #ef4444; } .qa-orange { background: #f97316; } .qa-purple { background: #7c3aed; }
.qa-yellow { background: #ca8a04; } .qa-teal { background: #0d9488; }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  padding: 0.3125rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500;
  background: #fff; border: 1px solid #e2e8f0; color: #475569; text-decoration: none;
}
.chip:hover { background: #f1f5f9; }
.chip.active { background: #2563eb; border-color: #2563eb; color: #fff; }

.sidebar-link.active { background: linear-gradient(90deg, #e8f1ff, #f4f8ff); box-shadow: inset 3px 0 0 #2563eb; }
.sidebar-section { letter-spacing: 0.06em; }
.table th { background: #f8fafc; }
