:root {
  --ink: #2d251f;
  --brown: #543a2a;
  --brown-dark: #32251e;
  --brown-soft: #72533e;
  --gold: #c9a45c;
  --gold-deep: #886634;
  --cream: #f7f3ec;
  --paper: #fffdf9;
  --line: #e8e0d5;
  --muted: #8e8378;
  --green: #2f9c71;
  --red: #b8473c;
  --shadow: 0 18px 50px rgba(54, 37, 23, .12);
  --radius: 16px;
  font-family: "Tahoma", "Arial", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--cream); font-size: 15px; line-height: 1.6; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(201,164,92,.55); outline-offset: 2px; }
.hidden { display: none !important; }
.mobile-only { display: none; }

/* Login */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 38px; background: radial-gradient(circle at 18% 14%, #fffdf9 0 18%, transparent 38%), var(--cream); }
.auth-card { width: min(1080px, 100%); min-height: 600px; display: grid; grid-template-columns: 1.08fr .92fr; direction: ltr; background: var(--paper); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
.auth-copy { direction: rtl; position: relative; background: linear-gradient(145deg, #5a3e2a 0%, #452e20 100%); padding: 42px 54px; color: #f9f0df; display: flex; flex-direction: column; justify-content: center; text-align: right; overflow: hidden; }
.auth-copy::before { content: ""; position: absolute; inset: 0; opacity: .13; background-image: linear-gradient(rgba(242, 208, 142,.3) 1px, transparent 1px), linear-gradient(90deg, rgba(242, 208, 142,.3) 1px, transparent 1px); background-size: 42px 42px; mask-image: linear-gradient(to bottom, black, transparent 90%); }
.auth-copy > * { position: relative; }
.auth-mark { display: flex; align-items: center; gap: 12px; color: var(--gold); letter-spacing: .22em; direction: ltr; }
.mark-letter, .sidebar-mark, .brand-mini-mark { display: grid; place-items: center; border: 1px solid rgba(249, 221, 161, .55); background: linear-gradient(135deg, #d6b36a, #947039); color: #44301f; font-weight: 800; }
.mark-letter { width: 42px; height: 42px; border-radius: 10px; font-family: Georgia, serif; font-size: 25px; }
.mark-word { font-family: Georgia, serif; font-size: 18px; }
.eyebrow { display: inline-block; color: #e6c987; font-size: 12px; font-weight: 700; letter-spacing: .06em; }
.eyebrow.gold { color: var(--gold-deep); }
.house-art { margin: 35px auto 17px; width: min(440px, 100%); }
.house-art svg { width: 100%; height: auto; fill: none; stroke: #d5b370; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 8px 9px rgba(0,0,0,.12)); }
.auth-copy h2 { font-size: 21px; margin: 15px 0 5px; font-weight: 500; }
.auth-copy p { color: #decbb2; margin: 0; font-size: 14px; }
.auth-footer-note { margin-top: auto; padding-top: 35px; border-top: 1px solid rgba(231, 197, 131, .25); display: flex; justify-content: space-between; color: #bfaa91; font-size: 11px; }
.auth-form-panel { direction: rtl; padding: 52px 54px 28px; display: flex; flex-direction: column; justify-content: center; background: #fff; }
.brand-mini { display: flex; align-items: center; gap: 10px; direction: rtl; margin-bottom: 64px; color: var(--brown); }
.brand-mini-mark { width: 38px; height: 38px; border-radius: 9px; font-family: Georgia, serif; font-size: 21px; }
.brand-mini strong, .brand-mini small { display: block; }
.brand-mini strong { font-size: 16px; letter-spacing: .08em; }
.brand-mini small { color: var(--muted); font-size: 11px; }
.auth-form-panel h1 { font-family: Georgia, "Tahoma", serif; font-size: clamp(28px, 3vw, 38px); line-height: 1.35; margin: 8px 0 4px; color: #171311; }
.form-lead { margin: 0 0 28px; color: var(--muted); font-size: 14px; }
.auth-form-panel label { display: block; margin: 17px 0 7px; font-weight: 700; font-size: 13px; color: #5d4d41; }
.auth-form-panel label b { color: var(--red); }
.input-wrap { position: relative; }
.input-wrap span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: #aa9d91; pointer-events: none; }
.input-wrap input { padding-right: 43px; }
input, select, textarea { border: 1px solid var(--line); background: #fff; border-radius: 10px; color: var(--ink); min-height: 42px; padding: 9px 13px; width: 100%; transition: border .2s, box-shadow .2s; }
input::placeholder, textarea::placeholder { color: #b1a8a0; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(201,164,92,.12); outline: none; }
.btn { border: 0; border-radius: 9px; min-height: 42px; padding: 9px 17px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; font-weight: 700; transition: transform .2s, filter .2s, background .2s; }
.btn:hover { filter: brightness(.97); transform: translateY(-1px); }
.btn-primary { background: var(--brown); color: white; }
.btn-dark { background: var(--brown-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--brown); border: 1px solid #cdbba4; }
.btn-wide { width: 100%; margin-top: 22px; min-height: 46px; }
.btn-arrow { font-size: 19px; line-height: 1; }
.security-note { display: flex; gap: 10px; align-items: flex-start; margin-top: 26px; padding: 13px; border-radius: 10px; background: #faf7f1; border: 1px solid #e8dccb; color: #8a7767; font-size: 11px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(47,156,113,.11); margin-top: 5px; }
.auth-legal { border-top: 1px solid #eee7df; color: #a99f96; font-size: 10px; padding-top: 16px; margin-top: auto; text-align: center; }
.code-input { direction: ltr; text-align: center; letter-spacing: .5em; font-size: 24px; font-weight: 800; }
.two-factor-actions { display: flex; justify-content: space-between; margin-top: 17px; }
.text-btn { border: 0; background: transparent; color: var(--gold-deep); font-weight: 700; padding: 0; }
.text-btn.muted { color: var(--muted); }
.form-message { color: var(--red); min-height: 22px; font-size: 13px; }

/* App shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) 278px; direction: ltr; background: var(--cream); }
.sidebar { grid-column: 2; grid-row: 1; direction: rtl; background: var(--brown-dark); color: #f7eddf; padding: 22px 14px 16px; display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; height: 100vh; z-index: 20; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 1px 8px 25px; border-bottom: 1px solid rgba(255, 247, 231, .1); }
.sidebar-mark { width: 34px; height: 34px; border-radius: 8px; font-family: Georgia, serif; font-size: 20px; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand strong { font-size: 15px; letter-spacing: .06em; }
.sidebar-brand small { color: #c3b4a7; font-size: 10px; }
.main-nav { display: grid; gap: 7px; padding-top: 25px; }
.nav-item { width: 100%; min-height: 43px; display: flex; align-items: center; gap: 12px; text-align: right; border: 0; border-radius: 8px; color: #cfc2b5; background: transparent; padding: 9px 12px; font-weight: 700; transition: .2s; }
.nav-item:hover, .nav-item.active { color: #fff; background: #c59d52; }
.nav-icon { width: 22px; text-align: center; font-size: 18px; color: #d8bb79; }
.nav-item.active .nav-icon { color: #fff; }
.nav-tag { margin-right: auto; font-size: 8px; color: #a48b70; background: rgba(255,255,255,.07); border-radius: 4px; padding: 2px 4px; }
.sidebar-spacer { flex: 1; }
.sidebar-status { padding: 15px 10px; display: flex; align-items: center; gap: 9px; color: #a9a098; font-size: 11px; }
.sidebar-user { display: flex; align-items: center; gap: 9px; padding: 13px 10px; border-radius: 9px; background: rgba(255,255,255,.07); }
.avatar { display: grid; place-items: center; border-radius: 50%; background: #eee9e1; color: var(--brown); font-weight: 800; }
.avatar-gold { width: 37px; height: 37px; background: var(--gold); color: var(--brown-dark); }
.avatar-small { width: 29px; height: 29px; font-size: 12px; }
.sidebar-user-copy { min-width: 0; flex: 1; }
.sidebar-user-copy strong, .sidebar-user-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-copy strong { font-size: 12px; }
.sidebar-user-copy small { color: #baada1; font-size: 10px; }
.main-content { direction: rtl; grid-column: 1; grid-row: 1; min-width: 0; padding: 0 30px 40px; }
.topbar { min-height: 67px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #ebe3d9; }
.breadcrumbs { display: flex; align-items: center; gap: 9px; color: #a2978d; font-size: 12px; }
.breadcrumbs strong { color: var(--brown); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { border: 0; background: transparent; color: #77695d; width: 35px; height: 35px; display: inline-grid; place-items: center; border-radius: 50%; position: relative; font-size: 18px; }
.icon-btn:hover { background: #eee7dc; color: var(--brown); }
.notification-dot { position: absolute; width: 6px; height: 6px; background: var(--red); border-radius: 50%; top: 5px; right: 5px; }
.user-chip { border: 0; background: transparent; color: var(--brown); display: flex; align-items: center; gap: 8px; font-weight: 700; }
.page-view { display: none; padding-top: 31px; }
.page-view.active-view { display: block; animation: page-in .25s ease-out; }
@keyframes page-in { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-heading h1 { font-family: Georgia, "Tahoma", serif; margin: 2px 0 1px; font-size: clamp(27px, 3vw, 38px); line-height: 1.35; color: #191411; }
.page-heading p { color: var(--muted); margin: 0; font-size: 13px; }
.heading-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin-bottom: 18px; }
.metric-card { min-height: 128px; position: relative; overflow: hidden; border: 1px solid #eee6dc; border-radius: 11px; background: #fff; padding: 18px 20px; box-shadow: 0 5px 18px rgba(69, 45, 25, .04); }
.metric-label, .metric-card small { display: block; color: #83766a; font-size: 12px; }
.metric-card strong { display: block; font-family: Georgia, serif; font-size: 33px; line-height: 1.25; color: var(--brown); margin: 6px 0 3px; }
.metric-card small { color: #a79c92; font-size: 10px; }
.metric-icon { position: absolute; left: 19px; bottom: 16px; color: #d1b57a; font-size: 22px; opacity: .85; }
.dashboard-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 17px; margin-bottom: 18px; }
.panel { border: 1px solid #eee6dc; border-radius: 11px; background: #fff; box-shadow: 0 5px 18px rgba(69, 45, 25, .035); }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 18px 20px; border-bottom: 1px solid #f0eae2; }
.panel-heading h2 { font-size: 16px; margin: 0 0 2px; color: #31271f; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 11px; }
.chart-panel, .quick-panel { min-height: 265px; }
.status-bars { display: grid; gap: 17px; padding: 25px 24px; }
.status-row { display: grid; grid-template-columns: 92px 1fr 35px; align-items: center; gap: 11px; color: #796b5f; font-size: 12px; }
.status-track { height: 8px; background: #f0e9df; border-radius: 20px; overflow: hidden; }
.status-fill { height: 100%; border-radius: inherit; background: var(--gold); }
.status-fill.brown { background: var(--brown-soft); }
.status-fill.green { background: #8ebc9b; }
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); padding: 18px; gap: 10px; }
.quick-actions button { border: 1px solid #eee6dc; background: #fbfaf7; border-radius: 9px; padding: 12px; text-align: right; color: var(--ink); }
.quick-actions button:hover { border-color: var(--gold); background: #fffaf0; }
.quick-actions span { display: block; color: var(--gold-deep); font-size: 20px; }
.quick-actions strong, .quick-actions small { display: block; }
.quick-actions strong { font-size: 12px; margin-top: 3px; }
.quick-actions small { color: var(--muted); font-size: 10px; }
.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
.crm-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.crm-table th { background: #faf8f4; color: #86786b; font-size: 11px; font-weight: 700; text-align: right; padding: 13px 15px; white-space: nowrap; }
.crm-table td { border-top: 1px solid #f0ebe4; padding: 13px 15px; color: #51453b; font-size: 12px; vertical-align: middle; }
.crm-table tbody tr:hover { background: #fffaf1; }
.customer-cell { display: flex; align-items: center; gap: 9px; min-width: 175px; }
.customer-cell .avatar { width: 31px; height: 31px; font-size: 11px; flex: 0 0 auto; }
.customer-cell strong, .customer-cell small { display: block; }
.customer-cell strong { color: #2d241e; }
.customer-cell small { color: #a3978d; font-size: 10px; }
.phone-cell { direction: ltr; text-align: right; color: #6c5b4c; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 4px; padding: 3px 7px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-high { color: #b64b3d; background: #fff0ed; }
.badge-medium { color: #9a7627; background: #fcf5df; }
.badge-low { color: #5b9270; background: #edf8ef; }
.badge-neutral { color: #796d62; background: #f2eee8; }
.badge-dark { color: #fff; background: var(--brown); }
.row-action { border: 1px solid #e6ddd2; color: var(--brown); border-radius: 5px; background: #fff; padding: 5px 9px; font-size: 11px; }
.row-action:hover { background: var(--brown); color: #fff; }
.panel > .pagination { border-top: 1px solid #f0ebe4; }
.pagination { display: flex; align-items: center; gap: 5px; padding: 13px 16px; justify-content: center; }
.page-btn { min-width: 29px; height: 29px; border-radius: 5px; border: 1px solid #e6ddd2; color: #77685a; background: white; font-size: 11px; }
.page-btn.active { color: #fff; background: var(--brown); border-color: var(--brown); }
.page-btn:disabled { opacity: .4; cursor: default; }
.empty-state { min-height: 150px; display: grid; place-items: center; padding: 30px; color: var(--muted); font-size: 13px; text-align: center; }
.loading-line { height: 11px; border-radius: 9px; background: linear-gradient(90deg, #f5eee5, #fff, #f5eee5); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.filters-panel { padding: 13px; display: flex; align-items: center; gap: 9px; margin-bottom: 15px; flex-wrap: wrap; }
.filters-panel .search-box { flex: 1 1 250px; }
.filters-panel select { max-width: 190px; min-width: 145px; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box span { position: absolute; right: 12px; color: #9f9287; }
.search-box input { padding-right: 35px; }
.timeline-panel { padding-bottom: 13px; }
.timeline { padding: 20px 25px; }
.activity-item { position: relative; padding: 0 28px 22px 0; border-right: 2px solid #eadfce; }
.activity-item:last-child { border-right-color: transparent; padding-bottom: 0; }
.activity-marker { position: absolute; right: -9px; top: 1px; width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; background: var(--gold); box-shadow: 0 0 0 1px #dbc49a; }
.activity-item h3 { margin: 0 0 3px; font-size: 13px; color: #4b3d31; }
.activity-item p { margin: 0 0 5px; color: #77695e; font-size: 12px; }
.activity-item small { color: #aa9e91; font-size: 10px; }
.priority-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.priority-card { background: #fff; border: 1px solid #eee6dc; border-radius: 11px; padding: 18px; box-shadow: 0 5px 18px rgba(69,45,25,.035); }
.priority-card .priority-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.priority-card h3 { font-size: 14px; margin: 0; }
.priority-card p { color: var(--muted); font-size: 11px; margin: 8px 0; }
.priority-card small { color: #ae9f91; font-size: 10px; }
.profile-card { max-width: 700px; padding: 28px; }
.profile-header { display: flex; align-items: center; gap: 15px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.profile-header .avatar { width: 58px; height: 58px; font-size: 20px; }
.profile-header h2 { margin: 0; font-size: 20px; }
.profile-header p { margin: 3px 0; color: var(--muted); direction: ltr; text-align: right; }
.profile-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; padding-top: 22px; }
.profile-field label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.profile-field strong { font-size: 13px; }

/* Modals and detail */
.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(42, 31, 23, .48); padding: 20px; }
.modal { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow: auto; border-radius: 14px; background: var(--paper); box-shadow: 0 25px 80px rgba(22, 14, 9, .28); }
.modal.large { width: min(980px, 100%); }
.detail-page-card { width: 100%; border-radius: 14px; background: var(--paper); box-shadow: 0 16px 42px rgba(22, 14, 9, .12); overflow: hidden; }
.modal-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 21px 24px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-family: Georgia, serif; font-size: 23px; }
.modal-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.modal-body { padding: 22px 24px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: #67584b; font-weight: 700; margin-bottom: 5px; }
.field label span { color: var(--red); }
.field textarea { min-height: 92px; resize: vertical; }
.modal-footer { display: flex; justify-content: flex-start; gap: 9px; padding: 17px 24px; border-top: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 16px; }
.detail-section { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 17px; }
.detail-section h3 { margin: 0 0 15px; font-size: 15px; }
.detail-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.detail-field label { display: block; color: var(--muted); font-size: 10px; }
.detail-field strong { display: block; font-size: 12px; margin-top: 2px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.danger-btn { color: var(--red); border-color: #e1b8b2; }
.detail-activity { margin-top: 16px; }
.detail-activity .timeline { padding: 10px 5px 0; }

.toast-stack { position: fixed; z-index: 200; top: 18px; left: 18px; display: grid; gap: 9px; width: min(340px, calc(100vw - 36px)); direction: rtl; }
.toast { padding: 13px 15px; border-radius: 9px; color: #fff; background: var(--brown-dark); box-shadow: 0 12px 28px rgba(0,0,0,.17); font-size: 12px; animation: toast-in .25s ease-out; }
.toast.success { background: #287a59; }
.toast.error { background: #9b3f38; }
@keyframes toast-in { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 1020px) {
  .auth-card { grid-template-columns: 1fr; max-width: 610px; }
  .auth-copy { display: none; }
  .auth-form-panel { min-height: 640px; }
  .brand-mini { margin-bottom: 44px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .auth-screen { padding: 12px; }
  .auth-form-panel { padding: 35px 24px 23px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; right: 0; top: 0; width: min(290px, 88vw); transform: translateX(105%); transition: transform .25s ease; box-shadow: -12px 0 40px rgba(0,0,0,.18); }
  .sidebar.open { transform: none; }
  .main-content { padding: 0 15px 30px; }
  .mobile-only { display: inline-grid; }
  .topbar { gap: 8px; }
  .topbar .mobile-only { margin-left: auto; }
  .breadcrumbs { display: none; }
  .topbar-actions { margin-right: auto; }
  .topbar-actions .user-chip span:last-child { display: none; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .heading-actions { width: 100%; }
  .heading-actions .btn { flex: 1; }
  .filters-panel { align-items: stretch; }
  .filters-panel select, .filters-panel .btn { max-width: none; flex: 1 1 145px; }
  .priority-grid { grid-template-columns: 1fr; }
  .profile-fields, .detail-fields, .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .metric-grid { gap: 8px; }
  .metric-card { padding: 13px; min-height: 105px; }
  .metric-card strong { font-size: 27px; }
  .metric-icon { left: 11px; bottom: 10px; }
  .page-view { padding-top: 22px; }
  .page-heading h1 { font-size: 30px; }
  .auth-form-panel { min-height: 620px; }
}
