/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif; background: #F5F7FA; color: #333; font-size: 14px; -webkit-font-smoothing: antialiased; }
input, button, textarea, select { font-family: inherit; font-size: inherit; }
a { text-decoration: none; color: inherit; }

:root {
  --primary: #1890FF;
  --primary-dark: #096DD9;
  --danger: #FF4D4F;
  --success: #52C41A;
  --warning: #FAAD14;
  --gray: #999;
  --gray-light: #F5F7FA;
  --border: #E8E8E8;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* ===== Layout ===== */
.app-container { min-height: 100vh; }
.page-wrapper { padding: 16px; padding-bottom: 20px; max-width: 960px; margin: 0 auto; }
.page-wrapper.has-tab-bar { padding-bottom: 70px; }

/* ===== Tab Bar ===== */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; height: 56px; background: #fff;
  border-top: 1px solid var(--border);
  max-width: 960px; margin: 0 auto;
}
@media (min-width: 960px) { .tab-bar { left: 50%; transform: translateX(-50%); } }
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--gray); font-size: 10px; transition: color .2s;
}
.tab-item.active { color: var(--primary); }
.tab-icon { font-size: 20px; line-height: 1.2; }
.tab-label { margin-top: 2px; }

/* ===== Cards ===== */
.card {
  background: #fff; border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}

/* ===== Typography ===== */
.text-bold { font-weight: 600; }
.text-gray { color: var(--gray); }
.text-small { font-size: 12px; }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* ===== Flexbox Helpers ===== */
.flex-row { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-1 { flex: 1; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-12 { margin-bottom: 12px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all .2s; line-height: 1.4;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: #E6F7FF; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* ===== Form ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; color: #666; font-weight: 500; }
.form-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #FAFAFA;
  transition: border-color .2s; outline: none;
}
.form-input:focus { border-color: var(--primary); background: #fff; }
.form-select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #FAFAFA;
  outline: none; appearance: auto;
}

/* ===== Tags / Badges ===== */
.tag {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 500; line-height: 1.6;
}
.tag-draft { background: #FFF7E6; color: #D46B08; }
.tag-published { background: #E6F7FF; color: #1890FF; }
.tag-closed { background: #F5F5F5; color: #999; }
.tag-submitted { background: #F6FFED; color: #52C41A; }

/* ===== Modal ===== */
.modal-mask {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s;
}
.modal-content {
  width: 90%; max-width: 480px; background: #fff; border-radius: 16px;
  padding: 24px; max-height: 85vh; overflow-y: auto;
  animation: slideUp .25s;
}
.modal-title { font-size: 17px; font-weight: 600; text-align: center; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 14px; }

/* ===== Loading ===== */
.loading-state { text-align: center; padding: 40px; color: var(--gray); }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.75); color: #fff; padding: 12px 24px;
  border-radius: 8px; font-size: 14px; z-index: 9999;
  animation: fadeIn .2s; pointer-events: none;
}

/* ===== Confirm Dialog ===== */
.confirm-mask {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.45); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.confirm-box {
  width: 80%; max-width: 320px; background: #fff; border-radius: 16px;
  padding: 24px; text-align: center;
}
.confirm-title { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.confirm-content { font-size: 14px; color: #666; margin-bottom: 24px; line-height: 1.6; }
.confirm-actions { display: flex; gap: 12px; }
.confirm-actions .btn { flex: 1; }

/* ====== LOGIN PAGE ====== */
.login-page { min-height: 100vh; background: #fff; padding: 0; }
.login-header {
  background: linear-gradient(135deg, #1890FF 0%, #36CFC9 100%);
  padding: 60px 24px 40px; color: #fff; text-align: center;
  border-radius: 0 0 40px 40px;
}
.login-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.login-header p { font-size: 14px; opacity: .85; }
.login-body { padding: 32px 24px; }
.login-form .form-group { margin-bottom: 20px; }
.login-form .form-input { padding: 14px 16px; font-size: 15px; border-radius: 12px; }
.login-form .btn { padding: 14px; font-size: 16px; border-radius: 12px; margin-top: 8px; }
.login-switch { text-align: center; margin-top: 20px; font-size: 14px; color: var(--gray); }
.login-switch a { color: var(--primary); font-weight: 500; margin-left: 4px; cursor: pointer; }

/* Role cards */
.role-cards { display: flex; gap: 10px; margin-bottom: 20px; }
.role-card {
  flex: 1; padding: 14px 8px; border: 2px solid var(--border); border-radius: 12px;
  text-align: center; cursor: pointer; transition: all .2s;
}
.role-card.active { border-color: var(--primary); background: #E6F7FF; }
.role-dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 auto 6px; }
.role-name { font-size: 13px; font-weight: 500; }

/* ====== HOME PAGE ====== */
.home-content { max-width: 640px; margin: 0 auto; }
.stats-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-card {
  flex: 1; background: #fff; border-radius: var(--radius); padding: 16px;
  text-align: center; box-shadow: var(--shadow);
}
.stat-num { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--gray); margin-top: 4px; }
.stat-draft .stat-num { color: #D46B08; }
.stat-published .stat-num { color: var(--primary); }
.stat-closed .stat-num { color: var(--gray); }

.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.action-card {
  background: #fff; border-radius: var(--radius); padding: 20px 16px;
  text-align: center; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .2s;
}
.action-card:hover { transform: translateY(-2px); }
.action-icon { font-size: 32px; margin-bottom: 8px; }
.action-label { font-size: 13px; font-weight: 500; }

.section-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* ====== PROCUREMENT LIST ====== */
.tabs { display: flex; gap: 0; background: #fff; border-radius: 10px; padding: 4px; margin-bottom: 16px; box-shadow: var(--shadow); }
.tab-btn {
  flex: 1; padding: 8px; text-align: center; font-size: 13px;
  border-radius: 8px; cursor: pointer; transition: all .2s;
  border: none; background: transparent; color: #666;
}
.tab-btn.active { background: var(--primary); color: #fff; font-weight: 500; }

.list-card { cursor: pointer; transition: transform .15s; }
.list-card:hover { transform: translateY(-1px); }
.list-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.list-meta { font-size: 12px; color: var(--gray); }
.list-meta span + span { margin-left: 12px; }

/* ====== PROCUREMENT EDIT ====== */
.category-section { margin-bottom: 16px; }
.category-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #fff; border-radius: 10px;
  cursor: pointer; box-shadow: var(--shadow); margin-bottom: 8px;
}
.category-bar { width: 4px; height: 20px; border-radius: 2px; margin-right: 10px; }
.category-name { font-size: 14px; font-weight: 600; }
.category-count { font-size: 12px; color: var(--gray); margin-left: 6px; }
.collapse-icon { transition: transform .2s; font-size: 16px; color: var(--gray); }
.collapse-icon.expanded { transform: rotate(90deg); }

.item-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #fff; border-radius: 8px;
  margin-bottom: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.item-name { font-size: 14px; }
.item-qty { font-size: 12px; color: var(--gray); margin-left: 8px; }
.item-actions { display: flex; gap: 8px; }
.item-actions .btn-sm { padding: 4px 10px; }

/* Bottom action bar */
.bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; padding: 12px 16px; border-top: 1px solid var(--border);
  z-index: 50; max-width: 960px; margin: 0 auto;
}
@media (min-width: 960px) { .bottom-bar { left: 50%; transform: translateX(-50%); } }
.bottom-bar .flex-row { gap: 12px; }

/* ====== QUOTATION FILL ====== */
.quote-item-card {
  background: #fff; border-radius: 10px; padding: 14px 16px;
  margin-bottom: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.quote-item-main { display: flex; align-items: center; justify-content: space-between; }
.quote-item-info { flex: 1; }
.quote-item-name { font-size: 14px; font-weight: 500; }
.quote-item-qty { font-size: 12px; color: var(--gray); margin-top: 2px; }
.price-input-wrapper {
  display: flex; align-items: center; background: #F9FAFC;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0 10px; height: 38px; transition: border-color .2s;
}
.price-input-wrapper:focus-within { border-color: var(--primary); background: #fff; }
.price-prefix { color: var(--danger); font-weight: 600; margin-right: 4px; }
.price-input {
  border: none; outline: none; background: transparent;
  width: 70px; text-align: right; font-size: 15px; font-weight: 600;
}
.price-unit { color: var(--gray); font-size: 13px; margin-left: 2px; }
.price-disabled { color: var(--gray); }
.quote-item-total { font-size: 12px; color: var(--primary); margin-top: 4px; text-align: right; }

.expand-toggle { font-size: 12px; color: var(--gray); margin-top: 8px; cursor: pointer; }
.extra-fields { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.extra-input { padding: 8px 10px; font-size: 13px; }

.quote-bottom { display: flex; align-items: center; justify-content: space-between; }
.total-label { font-size: 12px; color: var(--gray); }
.total-amount { font-size: 24px; font-weight: 700; color: var(--danger); }
.total-symbol { font-size: 14px; color: var(--danger); margin-right: 2px; }

/* ====== COMPARISON TABLE ====== */
.comparison-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.comparison-table {
  border-collapse: collapse; width: 100%; min-width: 500px;
  font-size: 13px; background: #fff; border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.comparison-table th, .comparison-table td {
  padding: 10px 12px; border: 1px solid #F0F0F0; text-align: center;
  white-space: nowrap;
}
.comparison-table th { background: #FAFAFA; font-weight: 600; position: sticky; top: 0; z-index: 2; }
.comparison-table .col-fixed { position: sticky; left: 0; z-index: 1; background: #fff; text-align: left; min-width: 120px; }
.comparison-table th.col-fixed { z-index: 3; background: #FAFAFA; }
.cell-lowest { background: #F6FFED; color: var(--success); font-weight: 600; }
.cell-highest { background: #FFF1F0; color: var(--danger); }
.total-row { font-weight: 600; background: #FAFAFA; }
.total-lowest { background: #F6FFED; color: var(--success); font-weight: 700; }
.category-header-row { background: #F0F5FF; }
.category-header-row td { font-size: 13px; color: #333; padding: 8px 12px !important; }
.category-bar-inline { display: inline-block; width: 4px; height: 14px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.category-subtotal-row { background: #FAFAFA; font-weight: 600; font-size: 13px; }
.category-subtotal-row td { border-top: 1px solid var(--border); }
.category-summary-row { padding: 4px 0; font-size: 13px; }

/* ====== PROFILE PAGE ====== */
.profile-header {
  background: linear-gradient(135deg, #1890FF, #36CFC9);
  border-radius: var(--radius); padding: 24px; color: #fff;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.profile-name { font-size: 20px; font-weight: 700; }
.profile-role {
  display: inline-block; margin-top: 6px; padding: 2px 12px;
  background: rgba(255,255,255,.25); border-radius: 10px; font-size: 12px;
}
.profile-info { margin-top: 12px; font-size: 13px; opacity: .9; }
.profile-info div + div { margin-top: 4px; }

.menu-list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.menu-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #F5F5F5; cursor: pointer;
  transition: background .15s;
}
.menu-item:last-child { border-bottom: none; }
.menu-item:hover { background: #FAFAFA; }
.menu-arrow { color: #CCC; }

/* ====== Excel Preview ====== */
.excel-preview { max-height: 50vh; overflow-y: auto; }
.excel-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.excel-table th, .excel-table td { padding: 6px 8px; border: 1px solid #F0F0F0; text-align: left; }
.excel-table th { background: #FAFAFA; font-weight: 600; }

/* ====== Responsive ====== */
@media (min-width: 768px) {
  .login-page { display: flex; align-items: center; justify-content: center; }
  .login-wrapper { width: 420px; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
  .stats-row { max-width: 600px; }
}
@media (min-width: 1024px) {
  .page-wrapper { padding: 24px; }
}
