
/* ===========================================
   فونت‌ها
   =========================================== */
@font-face {
  font-family: 'vazirmatn';
  src: url('/Vazirmatn-RD-UI-FD-Medium.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url('/MaterialIcons-Regular.ttf') format('truetype');
}
.micon,
button.bt-i {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: var(--icon-sz);
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}
.micon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.bt-i {
  width: var(--ctrl-h);
  min-width: var(--ctrl-h);
  padding: 0;
}

/* ===========================================
   متغیرها و تم
   =========================================== */
:root {
  --mdc-font-family: 'vazirmatn', 'Roboto', system-ui, sans-serif;
  --mdc-font-size: 14px;
  --mdc-line-height: 1.5;

  --p: #FFC107; /* primary */
  --s: #FF6F00; /* secondary */
  --d: #E53935; /* danger */
  --su: #2E7D32; /* success */
  --i: #039BE5; /* info */
  --w: #FF9800; /* warning */
  --c: #7C4DFF; /* creative */

  /* ── رنگ‌بندی محیطی (تم روشن) ── */
  --env-ok:     #2E7D32;
  --env-warn:   #E65100;
  --env-danger: #C62828;
  --env-info:   #0277BD;

  --mdc-primary: #1976d2;
  --mdc-on-primary: #ffffff;
  --mdc-primary-hover: #1565c0;
  --mdc-primary-focus: rgba(25, 118, 210, 0.25);

  --mdc-secondary: #455a64;
  --mdc-on-secondary: #ffffff;

  --mdc-surface: #ffffff;
  --mdc-background: #F8F5F2;
  --mdc-error: #d32f2f;
  --mdc-on-error: #000;
  --mdc-error-hover: #b71c1c;

  --mdc-text: #212121;
  --mdc-text-secondary: #757575;
  --mdc-border: rgba(0,0,0,0.12);
  --mdc-divider: rgba(0,0,0,0.08);

  --mdc-elevation-1: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --mdc-elevation-2: 0 3px 6px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
  --mdc-elevation-3: 0 6px 12px rgba(0,0,0,0.12), 0 3px 6px rgba(0,0,0,0.08);

  --mdc-radius-sm: 4px;
  --mdc-radius-md: 8px;
  --mdc-radius-lg: 12px;

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.625rem;
  --sp-4: 0.75rem;
  --sp-5: 1rem;
  --sp-6: 1.25rem;

  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.875rem;
  --fs-lg: 1rem;
  --fs-h1: 1.25rem;

  --ctrl-h: 2.25rem;
  --icon-sz: 1.125rem;
  --sidebar-w: 256px;

  --bg: var(--mdc-background);
  --surface: var(--mdc-surface);
  --text: var(--mdc-text);
  --primary: var(--mdc-primary);
  --on-primary: var(--mdc-on-primary);
  --border: var(--mdc-border);
  --danger: var(--mdc-error);
  --shadow: var(--mdc-elevation-1);
  --r-sm: var(--mdc-radius-sm);
  --r-md: var(--mdc-radius-md);
  --r-lg: var(--mdc-radius-lg);

  font-family: var(--mdc-font-family);
  font-size: var(--mdc-font-size);
  line-height: var(--mdc-line-height);
  color: var(--text);
  background: var(--bg);
  transition: background 0.25s, color 0.25s;
}

[data-theme="dark"] {
  --mdc-primary: #90caf9;
  --mdc-on-primary: #0d47a1;
  --mdc-primary-hover: #64b5f6;
  --mdc-primary-focus: rgba(144, 202, 249, 0.25);

  --mdc-secondary: #b0bec5;
  --mdc-surface: #1e1e1e;
  --mdc-background: #121212;
  --mdc-error: #ef5350;

  --mdc-text: #e0e0e0;
  --mdc-text-secondary: #9e9e9e;
  --mdc-border: rgba(255,255,255,0.12);
  --mdc-divider: rgba(255,255,255,0.08);

  --mdc-elevation-1: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --mdc-elevation-2: 0 3px 6px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.3);
  --mdc-elevation-3: 0 6px 12px rgba(0,0,0,0.6), 0 3px 6px rgba(0,0,0,0.4);

  --bg: var(--mdc-background);
  --surface: var(--mdc-surface);
  --text: var(--mdc-text);
  --primary: var(--mdc-primary);
  --on-primary: var(--mdc-on-primary);
  --border: var(--mdc-border);
  --shadow: var(--mdc-elevation-1);
  
  --label-width: 0px;
  --env-ok:     #66BB6A;
  --env-warn:   #FFB74D;
  --env-danger: #EF5350;
  --env-info:   #4FC3F7;
}

/* ===========================================
   ریست و چیدمان کلی
   =========================================== */
*, *::before, *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
}
.selectable {
	-webkit-user-select: text;
	-moz-user-select: text;
	-ms-user-select: text;
	user-select: text;
	-webkit-touch-callout: default;
}
html {
	direction: rtl;
	-webkit-text-size-adjust: 100%;
	height: 100%;
	overflow: hidden;
}
body, .app {

  padding-left:   env(safe-area-inset-left);
  padding-right:  env(safe-area-inset-right);

	height: 100vh;
	height: var(--app-height, 100vh);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	

}
a {
	color: var(--primary);
	text-decoration: none;
}
a:hover {
	text-decoration: underline;
}
::-webkit-scrollbar {
	width: 5px;
	height: 5px;
}
::-webkit-scrollbar-thumb {
	background: var(--mdc-text-secondary);
	border-radius: 4px;
}
header {
	flex-shrink: 0;
	background: var(--surface);
	padding: env(safe-area-inset-top) var(--sp-4) 0;
	height: calc(48px + env(safe-area-inset-top));
	display: flex;
	align-items: center;
	border-bottom: 1px solid var(--mdc-divider);
	margin-left: calc(-1 * env(safe-area-inset-left));
	margin-right: calc(-1 * env(safe-area-inset-right));
	padding-left: calc(var(--sp-4) + env(safe-area-inset-left));
	padding-right: calc(var(--sp-4) + env(safe-area-inset-right));
	z-index: 10;
}
main {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0;
}

button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--sp-1);
	height: var(--ctrl-h);
	min-width: var(--ctrl-h);
	padding: 0 var(--sp-2);
	font-family: inherit;
	font-size: var(--fs-sm);
	font-weight: 500;
	text-transform: none;
	letter-spacing: 0.025em;
	border: none;
	border-radius: var(--r-md);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	white-space: nowrap;
	box-shadow: var(--mdc-elevation-1);
	transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
button:hover { background: var(--border); box-shadow: var(--mdc-elevation-2); }
button:active {
	transform: scale(0.97);
	box-shadow: var(--mdc-elevation-1);
}
button:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 2px;
}
button.bt-p {
	background: var(--primary);
	color: var(--on-primary);
}
button.bt-p:hover {
	background: var(--mdc-primary-hover);
	box-shadow: var(--mdc-elevation-2);
}
.form-group, .fg {
	margin-top: 10px;
	width: 100%;
}
button.bt-p.bt-i {
	width: auto;
	min-width: var(--ctrl-h);
	padding: 0 var(--sp-3);
	font-family: inherit;
}
button.bt-danger {
	background: var(--danger);
	color: var(--mdc-on-error);
}
button.bt-danger:hover {
	background: var(--mdc-error-hover);
}
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
	width: 100%;
	height: var(--ctrl-h);
	padding: 0 var(--sp-2);
	font-family: inherit;
	font-size: var(--fs-base);
	line-height: 1.4;
	border: 1px solid var(--mdc-border);
	border-radius: var(--r-sm);
	background: var(--surface);
	color: var(--text);
	outline: none;
	transition: border-color 0.2s, box-shadow 0.2s;
}
textarea {
	height: auto;
	min-height: calc(var(--ctrl-h) * 2);
	padding: var(--sp-1) var(--sp-2);
	resize: vertical;
}
input:focus,
select:focus,
textarea:focus {
	border-color: var(--primary);
	box-shadow: 0 0 0 2px var(--mdc-primary-focus);
}
label {
	display: block;
	margin-bottom: var(--sp-1);
	font-size: var(--fs-xs);
	font-weight: 500;
	color: var(--mdc-text-secondary);
}
/* کارت */
.crd {
	background: var(--surface);
	border-radius: var(--r-lg);
	padding: var(--sp-3);
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	border: 1px solid var(--mdc-divider);
}
.crd2 {
	background: var(--surface);
	border-radius: var(--r-lg);
	padding: var(--sp-3);
	display: flex;
	gap: var(--sp-2);
	border: 1px solid var(--mdc-divider);
}
.crd0 {
	background: var(--surface);
	border-radius: var(--r-lg);
	padding: var(--sp-3);
	border: 1px solid var(--mdc-divider);
}
.icon-box {
	width: 48px;
	height: 48px;
	flex-shrink: 0;
	border-radius: var(--r-lg);
	display: flex;
	align-items: center;
	justify-content: center;
}
.icon-box span {
    font-size: 24px;
}
/* دیالوگ */
dialog {
	border: none;
	border-radius: var(--r-lg);
	padding: var(--sp-4);
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--mdc-elevation-3);
	max-width: 400px;
	width: 90%;
	margin: auto;
	animation: dialogIn 0.2s ease;
}
dialog[open] {
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
}
dialog::backdrop {
	background: rgba(0,0,0,0.4);
}
@keyframes dialogIn {
	from { opacity: 0; transform: scale(0.95); }
}
.dlg-actions {
	display: flex;
	gap: var(--sp-2);
	justify-content: flex-end;
	margin-top: var(--sp-2);
}

@keyframes spin {
	from { transform: rotate(0deg); }
	to   { transform: rotate(360deg); }
}

/* Toast */
.toast {
	bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
	position: fixed;
	left: 50%;
	transform: translateX(-50%);
	background: #323232;
	color: #fff;
	padding: var(--sp-2) var(--sp-4);
	border-radius: 20px;
	box-shadow: var(--mdc-elevation-2);
	z-index: 9999;
	animation: slideUp 0.3s ease;
}
@keyframes slideUp {
	from { opacity: 0; transform: translateX(-50%) translateY(10px); }
}
.child { all: inherit; }

#top-content { flex: 0 0 auto; border-bottom: 1px solid var(--mdc-divider); background: var(--surface); z-index: 5; }
#top-content>div { display: flex; padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); min-width: 100%; }
#center-content {
	flex: 1;
	overflow-y: auto;
	padding: var(--sp-2);
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	animation: pageIn 0.15s ease;
	min-height: 0;
}
#down-content { flex: 0 0 auto; border-top: 1px solid var(--mdc-divider); background: var(--surface); z-index: 5; padding-bottom: env(safe-area-inset-bottom);}
#down-content>div { display: flex; padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); min-width: 100%; }

@keyframes pageIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* لودینگ بار */
body.is-loading::after {
	content: '';
	position: fixed;
	top: 0;
	right: 0;
	left: 0;
	height: 3px;
	background: var(--primary);
	z-index: 999;
	animation: loadingSlide 1.5s ease infinite;
}
@keyframes loadingSlide {
	0% { transform: translateX(-100%); }
	100% { transform: translateX(100%); }
}

/* کلاس‌های کمکی */
[x-cloak] { display: none !important; }
html, body { overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; }
button, a, input, select, textarea { touch-action: manipulation; }

input, textarea, [contenteditable] {
	-webkit-user-select: text !important;
	-moz-user-select: text !important;
	-ms-user-select: text !important;
	user-select: text !important;
	-webkit-touch-callout: default !important;
}
.text-center { text-align: center; }
.page-center { display: flex; align-items: center; justify-content: center; flex: 1; width: 100%; min-height: 0; }
.login-card { width: 95%; max-width: min(95%, 360px); padding: var(--sp-5); }
.login-title { text-align: center; color: var(--primary); margin-bottom: var(--sp-4); font-size: var(--fs-h1); font-weight: 500; }
.login-error { min-height: 1.2rem; font-size: var(--fs-xs); color: var(--danger); margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mr-2 { margin-right: var(--sp-2); }
.htmx-request { pointer-events: none; opacity: 0.6; cursor: not-allowed; }
#lr, .loader { animation: spin 1s linear infinite; }

#page-title { font-size: 1.2rem; margin: 0; width: 100%; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

button.bt-a { background-color: transparent; box-shadow: none; }
button.bt-a:hover { background: var(--border); box-shadow: none; }

/* کانتکست منو */
.ctx {
	position: fixed;
	right: auto;
	top: auto;
	z-index: 100;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--r-md);
	box-shadow: var(--mdc-elevation-1);
	font-size: var(--fs-sm);
	max-width: calc(100vw - 16px);
	max-height: calc(100vh - 16px);
	overflow-y: auto;
	z-index: 9999 !important;
}
.ctx-i {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 16px 16px;
	width: 100%;
	border-bottom: 1px solid var(--mdc-border);
	background: none;
	text-align: right;
	cursor: pointer;
	white-space: nowrap;
	color: var(--text);
	font-size: inherit;
	font-family: inherit;
}
.ctx-i:hover {
	border-radius: var(--r-md);
	background: var(--border);
}

.bottom-sheet-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,0.4);
	z-index: 50;
	display: flex;
	align-items: flex-end;
}
.bottom-sheet {
	background: var(--surface);
	width: 100%;
	max-height: 70vh;
	overflow-y: auto;
	border-radius: var(--r-md) var(--r-md) 0 0;
	box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
	padding: 8px 0;
	z-index: 100;
}

.menu-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50; }
.sidebar {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	width: var(--sidebar-w);
	background: var(--surface);
	padding: var(--sp-3);
	padding-top: calc(var(--sp-3) + env(safe-area-inset-top));
	padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
	box-shadow: var(--mdc-elevation-2);
	z-index: 60;
	transform: translateX(100%);
	transition: transform 0.25s ease;
	overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.menu-item { padding: var(--sp-1) 0; cursor: pointer; }
.menu-sub { padding-right: var(--sp-3); font-size: var(--fs-xs); opacity: 0.7; }
.sidebar a { display: block; padding: var(--sp-2); border-radius: var(--r-md); color: var(--text); transition: background 0.15s; }
.sidebar a:active { background: rgba(128,128,128,0.15); }

.tbl-wrap {
	overflow-x: auto;
	border-radius: var(--r-md);
	border: 1px solid var(--mdc-divider);
}
table.tbl {
	width: 100%;
	border-collapse: collapse;
	background: var(--surface);
	border-spacing: 0;
}
table.tbl thead th {
	position: sticky;
	top: 0;
	background: var(--surface);
	padding: var(--sp-1) var(--sp-2);
	font-size: var(--fs-xs);
	font-weight: 600;
	text-align: right;
	border-bottom: 2px solid var(--mdc-border);
	white-space: nowrap;
	z-index: 2;
	color: var(--mdc-text);
	border-radius: var(--r-md);
	box-shadow: var(--mdc-elevation-1);
}
table.tbl tbody td {
	padding: var(--sp-1) var(--sp-2);
	border-bottom: 1px solid var(--mdc-divider);
	font-size: var(--fs-sm);
}
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover {
	/* background: rgba(0,0,0,0.03); */
}

@media (max-width: 768px) {
	table.tbl thead { display: none; }
	table.tbl, table.tbl tbody, table.tbl tr, table.tbl td {
		display: block;
	}
	table.tbl tr {
		margin-top: var(--sp-2);
		padding: var(--sp-2);
		border: 1px solid var(--mdc-border);
		border-radius: var(--r-md);
		background: var(--surface);
	}
	table.tbl tr:first-child { margin-top: 0; }
	table.tbl {
		background: transparent;
	}
	table.tbl td {
		display: flex;
		gap: var(--sp-2);
		align-items: baseline;
		border: none !important;
		background: transparent;
	}
	table.tbl td::before {
		content: attr(data-label);
		display: inline-block;
		 width: var(--label-w, 78px);
		text-align: left;
		font-weight: 600;
		color: var(--primary);
		flex-shrink: 0;
	}
}
@media (max-width: 768px) {
    table.tbl tbody tr {
        position: relative;
    }
    table.tbl tbody td.td-action {
        position: absolute;
        top: var(--sp-2);
        left: var(--sp-2);
        display: block;
        width: auto;
        padding: 0;
        border: none !important;
        background: transparent;
    }
    table.tbl tbody td.td-action::before {
        display: none;
    }
    table.tbl tbody td.td-action button {
        margin: 0;
        min-width: var(--ctrl-h);
        height: var(--ctrl-h);
    }
}
