:root {
  --zoho-sidebar: #1b2a4a;
  --zoho-sidebar-hover: #243556;
  --zoho-sidebar-active: #2f7bdc;
  --zoho-bg: #f3f4f8;
  --zoho-blue: #2f7bdc;
  --zoho-blue-dark: #2563b8;
  --zoho-border: #e4e7ef;
  --zoho-text: #1f2937;
  --zoho-muted: #6b7280;
}

* { box-sizing: border-box; }
body.app-body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--zoho-bg);
  color: var(--zoho-text);
  min-height: 100vh;
}

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.app-sidebar {
  width: 240px;
  background: var(--zoho-sidebar);
  color: #c8d3e8;
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  overflow-y: auto;
}
@media (min-width: 1024px) {
  .app-sidebar { display: flex; }
  .app-main-wrap { margin-left: 240px; }
}

.sidebar-brand {
  padding: 18px 20px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand span {
  background: var(--zoho-blue);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-section-label {
  padding: 10px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #7a8db5;
  font-weight: 600;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 20px;
  color: #c8d3e8;
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: background .15s;
}
.nav-link:hover { background: var(--zoho-sidebar-hover); color: #fff; }
.nav-link.active {
  background: rgba(47,123,220,.25);
  color: #fff;
  border-left-color: var(--zoho-blue);
  font-weight: 600;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-sub { padding-left: 12px; }
.nav-sub .nav-link { font-size: 13px; padding-left: 28px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: #7a8db5;
}

/* Main area */
.app-main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
  background: #fff;
  border-bottom: 1px solid var(--zoho-border);
  padding: 0 16px;
  height: 56px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
}
@media (max-width: 640px) {
  .app-topbar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }
  .topbar-search { grid-column: 1 / -1; max-width: none !important; }
  .topbar-left { grid-column: 1; }
  .topbar-user-menu { grid-column: 2; grid-row: 1; }
}
.topbar-left { min-width: 0; }
.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--zoho-text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 360px;
  background: var(--zoho-bg);
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 7px 12px;
}
.topbar-search input {
  border: none;
  background: transparent;
  flex: 1;
  font-size: 14px;
  outline: none;
  min-width: 0;
}
.topbar-search svg { color: var(--zoho-muted); flex-shrink: 0; }

.topbar-user-menu { position: relative; }
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--zoho-border);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  color: var(--zoho-text);
  transition: border-color .15s, box-shadow .15s;
}
.user-menu-btn:hover { border-color: var(--zoho-blue); box-shadow: 0 2px 8px rgba(47,123,220,.1); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--zoho-blue);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.user-avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.user-name { font-weight: 500; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 480px) { .user-name { display: none; } }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 100;
  overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--zoho-bg);
}
.user-dropdown-name { font-weight: 600; font-size: 14px; }
.user-dropdown-email { font-size: 12px; color: var(--zoho-muted); margin-top: 2px; }
.user-dropdown-divider { height: 1px; background: var(--zoho-border); }
.user-dropdown-item {
  display: block;
  padding: 11px 16px;
  font-size: 14px;
  color: var(--zoho-text);
  text-decoration: none;
}
.user-dropdown-item:hover { background: var(--zoho-bg); }
.user-dropdown-item-form { margin: 0; }
.user-dropdown-item.logout {
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: #dc2626;
  padding: 11px 16px;
}
.user-dropdown-item.logout:hover { background: #fef2f2; }

.app-content {
  padding: 20px;
  padding-bottom: 88px;
  flex: 1;
}
@media (min-width: 1024px) {
  .app-content { padding-bottom: 24px; }
}

/* Cards & components */
.card {
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--zoho-border);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
.btn-primary { background: var(--zoho-blue); color: #fff; border-color: var(--zoho-blue); }
.btn-primary:hover { background: var(--zoho-blue-dark); }
.btn-secondary { background: #fff; color: var(--zoho-text); border-color: var(--zoho-border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: var(--zoho-text);
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--zoho-blue);
  box-shadow: 0 0 0 3px rgba(47,123,220,.15);
}
.form-input[readonly] { background: #f9fafb; color: var(--zoho-muted); }

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--zoho-muted); margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--zoho-border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--zoho-muted);
  font-weight: 600;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--zoho-border);
}
.data-table tr:hover td { background: #fafbfc; }
.data-table a { color: var(--zoho-blue); text-decoration: none; font-weight: 500; }

/* Mobile bottom nav */
.mobile-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--zoho-border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
@media (min-width: 1024px) { .mobile-nav { display: none; } }
.mobile-nav a {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  font-size: 10px;
  color: var(--zoho-muted);
  text-decoration: none;
}
.mobile-nav a.active { color: var(--zoho-blue); font-weight: 600; }
.mobile-nav svg { width: 22px; height: 22px; display: block; margin: 0 auto 2px; }

/* Bill item rows */
.item-row {
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fafbfc;
}
.item-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 14px;
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .form-grid-2 { grid-template-columns: 1fr; } }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 420px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0,0,0,.15);
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 16px; }

.sticky-footer {
  position: sticky;
  bottom: 72px;
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
  margin-top: 16px;
  z-index: 10;
}
@media (min-width: 1024px) { .sticky-footer { bottom: 12px; } }

.list-card {
  display: block;
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
}
.list-card:hover { border-color: var(--zoho-blue); box-shadow: 0 2px 8px rgba(47,123,220,.08); }

.page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--zoho-blue);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--zoho-border);
}
.back-link:hover { background: #f0f6ff; border-color: var(--zoho-blue); }
.page-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.sub-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
}
.sub-nav a {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--zoho-muted);
  text-decoration: none;
}
.sub-nav a:hover { background: #f3f4f6; color: var(--zoho-text); }
.sub-nav a.active { background: var(--zoho-blue); color: #fff; }
.sub-nav-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #d97706;
  color: #fff;
  vertical-align: middle;
}
.sub-nav a.active .sub-nav-badge { background: #fff; color: var(--zoho-blue); }

.metric-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (min-width: 640px) { .metric-row { grid-template-columns: repeat(4, 1fr); } }
.metric-box {
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.metric-box .label { font-size: 11px; color: var(--zoho-muted); text-transform: uppercase; letter-spacing: .04em; }
.metric-box .value { font-size: 20px; font-weight: 700; margin-top: 4px; }

.item-list-card {
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}
.item-list-card .code { color: var(--zoho-blue); font-weight: 600; font-size: 13px; }
.item-list-card .meta { font-size: 13px; color: var(--zoho-muted); margin-top: 4px; }
.item-list-card .metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
}
.item-list-card .metrics span { display: block; color: var(--zoho-muted); font-size: 10px; margin-bottom: 2px; }

.detail-rows { display: grid; gap: 0; font-size: 14px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--zoho-border);
}
.detail-row:last-child { border-bottom: none; }
.detail-row-divider { border-top: 1px solid var(--zoho-border); margin-top: 4px; padding-top: 14px; }
.detail-label { color: var(--zoho-muted); flex-shrink: 0; }
.detail-row > span:last-child,
.detail-row > strong { text-align: right; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  background: #fff;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 8px 12px;
}
.search-bar input {
  flex: 1;
  border: none;
  font-size: 14px;
  outline: none;
  min-width: 0;
}
.search-bar svg { color: var(--zoho-muted); flex-shrink: 0; }

.bill-items-wrap {
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
}
.bill-items-table { margin: 0; }
.bill-items-table td { vertical-align: middle; padding: 8px 10px; }
.bill-items-table thead { position: sticky; top: 0; background: #f9fafb; z-index: 2; }

.bill-link-list { display: grid; gap: 8px; }
.bill-link-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--zoho-bg);
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.bill-link-item input { width: 18px; height: 18px; }

/* Payment form (Zoho-style) */
.payment-form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (min-width: 768px) { .payment-form-grid { grid-template-columns: repeat(3, 1fr); } }
.form-field .required::after { content: ' *'; color: #dc2626; }
.input-prefix {
  display: flex;
  align-items: center;
  border: 1px solid var(--zoho-border);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.input-prefix span {
  padding: 0 10px;
  background: var(--zoho-bg);
  color: var(--zoho-muted);
  font-size: 14px;
  border-right: 1px solid var(--zoho-border);
  align-self: stretch;
  display: flex;
  align-items: center;
}
.input-prefix input { border: none !important; border-radius: 0 !important; }
.credit-banner {
  margin-top: 16px;
  padding: 12px 14px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
  font-size: 14px;
}
.payment-bills-table .bill-pay-input:disabled { background: #f3f4f6; opacity: .7; }
.payment-totals {
  padding: 16px 20px;
  border-top: 1px solid var(--zoho-border);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.payment-totals-row {
  display: flex;
  justify-content: space-between;
  gap: 40px;
  font-size: 14px;
  min-width: 260px;
}
.payment-totals-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 280px;
}
.payment-totals-row.excess { color: #c2410c; font-size: 15px; margin-top: 4px; }

/* Inventory */
.inventory-toolbar { margin-bottom: 16px; display: flex; flex-direction: column; gap: 10px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--zoho-border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  color: var(--zoho-muted);
  transition: all .15s;
}
.filter-chip:hover { border-color: var(--zoho-blue); color: var(--zoho-blue); }
.filter-chip.active { background: var(--zoho-blue); border-color: var(--zoho-blue); color: #fff; }
.inv-thumb {
  width: 56px; height: 56px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--zoho-border);
  display: block;
}
.inv-thumb img { width: 100%; height: 100%; object-fit: cover; }
.inv-thumb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--zoho-bg);
  color: var(--zoho-muted);
}
.inv-thumb-lg { width: 88px; height: 88px; }
.item-image-picker { flex-shrink: 0; }
.item-image-trigger {
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  display: block;
}
.item-image-trigger .inv-thumb-empty-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: var(--zoho-bg);
  color: var(--zoho-muted);
}
.inventory-item-body {
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  display: block;
}
.inventory-item-body:hover .code { text-decoration: underline; }
.metrics-compact { grid-template-columns: repeat(4, 1fr); }
.metrics-compact span { display: block; color: var(--zoho-muted); font-size: 10px; margin-bottom: 2px; }
.image-picker-modal { max-width: 420px; width: calc(100% - 32px); }
.image-picker-preview-wrap {
  background: #f9fafb;
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  overflow: hidden;
}
.image-picker-preview-wrap img {
  max-width: 100%;
  max-height: 320px;
  object-fit: contain;
}
.image-picker-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--zoho-muted);
  padding: 24px;
}
.image-picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.expense-type-box {
  border: 1px solid var(--zoho-border);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fafafa;
}
.expense-type-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
}
.expense-type-option input { margin-top: 3px; }
.expense-bill-picker {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--zoho-border);
}
.expense-bill-picker.open { display: block; }
.expense-bill-list {
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  gap: 6px;
  margin-top: 8px;
}
.expense-bill-list label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--zoho-border);
  background: #fff;
}

.status-badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
  display: inline-block;
}
.status-badge.status-paid { background: #ecfdf5; color: #059669; }
.status-badge.status-void { background: #fef2f2; color: #dc2626; }
tr.row-void { opacity: .65; }
tr.row-void td { text-decoration: line-through; text-decoration-color: rgba(0,0,0,.2); }
tr.row-void td a { text-decoration: line-through; }

.login-page { min-height:100vh; display:flex; align-items:center; justify-content:center; background:linear-gradient(135deg,#1b2a4a 0%,#2f4a7a 100%); padding:20px; }
.login-box { background:#fff; border-radius:10px; padding:32px; width:100%; max-width:400px; box-shadow:0 20px 50px rgba(0,0,0,.25); }
.login-logo { font-size:22px; font-weight:700; color:#1b2a4a; margin-bottom:4px; }
.login-sub { color:#6b7280; font-size:14px; margin-bottom:24px; }
