/* Light blue theme and typography */
:root{
	--bg: #0d1524;
	--card-bg: #121c2f;
	--text: #e4ecf8;
	--muted: #97abc8;
	--border: #2a3b58;
	--primary: #4ea1ff;
	--primary-dark: #2f81de;
	--primary-10: rgba(78,161,255,0.18);
	--table-header: #16243a;
	--hover: #1a2a42;
	--shadow: 0 12px 30px rgba(2, 7, 17, 0.42);
	--soft-shadow: 0 8px 18px rgba(2, 7, 17, 0.32);
	--danger: #e53935;
	--success: #3ebd74;
}

html {
	font-size: 14.5px;
	color-scheme: dark;
}
body {
	font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
	background:
		radial-gradient(1200px 500px at -10% -20%, #1f3558 0%, transparent 60%),
		radial-gradient(1200px 500px at 110% -15%, #1d2f4b 0%, transparent 58%),
		var(--bg);
	color: var(--text);
	line-height: 1.6;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	margin: 0;
	min-height: 100vh;
}

#app {
	max-width: 1280px;
	margin: 28px auto;
	background: var(--card-bg);
	border-radius: 16px;
	border: 1px solid var(--border);
	box-shadow: var(--shadow);
	padding: 24px 24px 28px;
}

.site-footer {
	width: 100%;
	box-sizing: border-box;
	margin-top: 24px;
	padding: 18px 0 0;
	border-top: 1px solid var(--border);
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 0;
	flex-wrap: wrap;
	text-align: center;
	font-size: 13px;
	font-weight: 500;
	letter-spacing: .02em;
	color: var(--muted);
}

.site-footer span {
	color: var(--muted);
}

.site-footer a {
	color: var(--muted);
	text-decoration: none;
}

.site-footer a:hover {
	color: #dce9fb;
	text-decoration: underline;
}

header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 20px;
	padding-bottom: 14px;
	border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.6rem; margin: 0; font-weight: 700; letter-spacing: .2px; color: var(--text); }

/* Buttons */
button {
	font: inherit;
	border: 1px solid transparent;
	border-radius: 10px;
	padding: 8px 14px;
	cursor: pointer;
	transition: all .15s ease;
	font-weight: 600;
	background: linear-gradient(180deg, #18263d 0%, #132033 100%);
	color: #dce9fb;
	border-color: #314766;
	box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 2px 8px rgba(3, 8, 18, 0.24);
}
button:disabled { opacity: .6; cursor: not-allowed; }
button:hover {
	transform: translateY(-1px);
	border-color: #45638e;
	background: linear-gradient(180deg, #1d304d 0%, #172741 100%);
}
button:active {
	transform: translateY(0);
	background: linear-gradient(180deg, #142237 0%, #101b2c 100%);
}
nav {
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
}
nav button {
	margin-right: 0;
	background: linear-gradient(180deg, #4ea1ff 0%, #2f81de 100%);
	color: #fff;
	box-shadow: 0 4px 12px rgba(14, 54, 99, .45);
}
nav button:hover {
	transform: translateY(-1px);
	background: linear-gradient(180deg, #67b0ff 0%, #3a8ce6 100%);
}
nav button:last-child { margin-right: 0; }
nav button.active { background: var(--primary-dark); }

.assoc-btn { background: var(--primary); color: #fff; padding: 6px 12px; border-radius: 8px; }
.assoc-btn:hover { background: var(--primary-dark); }
.assoc-btn:disabled { background: #c7d7ee; }
.debug-btn { background: #607d8b; color: #fff; padding: 6px 12px; border-radius: 8px; }

button[style*="background:#607d8b"] {
	background: linear-gradient(180deg, #58718d 0%, #3f556e 100%) !important;
	color: #f4f8ff !important;
	border-color: #6d87a3 !important;
}

button[style*="background:#b91c1c"],
button[style*="background:#fee2e2"] {
	background: linear-gradient(180deg, #8f2c37 0%, #70202a 100%) !important;
	color: #ffe3e7 !important;
	border-color: #a84551 !important;
}

.tab { margin-top: 14px; }
.tab h2 {
	font-size: 1.28rem;
	margin: 0 0 10px 0;
	font-weight: 700;
	padding-left: 10px;
	border-left: 4px solid #8eb7e5;
}

/* Forms */
.form-row { display:flex; flex-wrap: wrap; gap: 10px; align-items: center; }
input, select, textarea {
	font: inherit;
	padding: 8px 12px;
	border: 1px solid var(--border);
	border-radius: 10px;
	outline: none;
	background: #0f1a2c;
	color: var(--text);
	transition: box-shadow .15s ease, border-color .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-10); }

input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="file"] {
	min-height: 40px;
	color-scheme: dark;
}

input[type="file"] {
	padding: 6px;
	background: #0f1a2c;
	color: #d8e5f8;
}

input[type="file"]::file-selector-button {
	font: inherit;
	margin-right: 10px;
	padding: 8px 12px;
	border-radius: 8px;
	border: 1px solid #35517a;
	background: linear-gradient(180deg, #1a2a43 0%, #142238 100%);
	color: #dce9fb;
	cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
	background: linear-gradient(180deg, #213553 0%, #192b45 100%);
}

/* Field block with label on top */
.field { display:flex; flex-direction: column; gap: 6px; }
.field label { font-size: .9rem; color: #334155; }
.field label { color: #b6c8e2; }

/* Ad section layout */
.ad-section { margin-top: 4px; }
.ad-grid { display:grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); gap: 12px; }
.ad-card { background:#101a2b; border:1px solid var(--border); border-radius:12px; padding:12px; box-shadow: var(--soft-shadow); }
.ad-card h4 { margin: 2px 0 8px; font-size: 1rem; color:#1e3a5f; }
.ad-card h4 { color:#d4e3f8; }
.ad-card label { display:block; font-size:.85rem; color:#99aecb; margin-top:6px; }
.preview { max-width: 220px; max-height: 120px; border:1px solid var(--border); border-radius:8px; object-fit: cover; }

/* Basic info grid (top red box) */
.basic-grid { width:100%; display:grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap:12px; align-items:end; }
.basic-grid .span-2 { grid-column: span 2; }
.basic-grid .span-3 { grid-column: span 3; }
.basic-grid .span-4 { grid-column: span 4; }
.field input, .field select { width:100%; }

/* Right-side large cover panel */
.cover-panel{ grid-column: 5 / 7; grid-row: 1 / span 4; display:flex; flex-direction: column; gap: 8px; align-items: stretch; }
.cover-panel label{ font-size: .9rem; color:#334155; }
.preview.cover{ width: 100%; max-width: 100%; height: 220px; max-height: 260px; object-fit: cover; border-radius: 10px; }

@media (max-width: 980px) {
	.ad-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
	.basic-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
	.cover-panel{ grid-column: 1 / -1; grid-row: auto; }
	.preview.cover{ height: 180px; }
}

/* Flash highlight when loading edit */
.flash { animation: flash-bg 1.2s ease 1; }
@keyframes flash-bg {
	0% { box-shadow: 0 0 0 0 rgba(30,136,229,0.25); }
	50% { box-shadow: 0 0 0 6px rgba(30,136,229,0.12); }
	100% { box-shadow: 0 0 0 0 rgba(30,136,229,0); }
}

/* Tables */
table { width: 100%; border-collapse: collapse; margin-top: 10px; background: #101a2a; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: .95rem; }
th {
	background: linear-gradient(180deg, #1b2d47 0%, #16263d 100%);
	color: #d8e5f8;
	font-weight: 700;
	position: sticky;
	top: 0;
	z-index: 1;
}
tr:nth-child(even) { background: #0f1929; }
tr:hover { background: var(--hover); }

.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0,0,0,.08); }
.avatar { box-shadow: 0 0 0 2px #17233a, 0 1px 4px rgba(0,0,0,.28); }

/* Sign in */
.signin { display:flex; align-items:center; justify-content:center; margin: 16px 0; }
.signin .card { width: 100%; max-width: 440px; border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: var(--card-bg); box-shadow: var(--shadow); }
.signin h3 { margin: 0 0 8px 0; font-size: 1.2rem; }
.signin p { margin: 0 0 12px 0; color: var(--muted); }
.signin input { width: 100%; }
.signin .actions { display:flex; align-items:center; gap: 12px; margin-top: 12px; }
.signin .actions .link { background: transparent; color: var(--primary); }
.signin .actions .link:hover { text-decoration: underline; }
.signin .msg { margin-top: 8px; color: var(--danger); font-size: .9rem; }

/* status indicator */
.status-dot { display:inline-block; width:12px; height:12px; border-radius:50%; margin-right:8px; vertical-align:middle; box-shadow: 0 0 0 2px #fff; }
.status-online { background: var(--success); } /* green for idle/online */
.status-offline { background: var(--danger); } /* red for error/offline */
/* Blue for running (state=4) */
.status-running { background: #1976d2; }
/* Gray for online but non-idle (state = 0) */
.status-gray { background: #9e9e9e; }

/* global message bar */
.msg-bar{
	border: 1px solid var(--border);
	background: #2c1b22;
	color: #ffc7d0;
	padding: 8px 12px;
	border-radius: 8px;
	margin: 8px 0 4px;
	box-shadow: 0 2px 8px rgba(229,57,53,.08);
}

/* Modal system */
#rechargeModal,
#decrementModal,
#memberModal,
#associateModal,
#debugModal,
#assignStoreModal,
#orgAttachStoreModal,
#pwdModal,
#permModal,
#activityModal {
	backdrop-filter: blur(6px);
	background: rgba(3, 9, 18, 0.62) !important;
	padding: 20px;
	box-sizing: border-box;
	z-index: 1200;
}

#rechargeModal > div,
#decrementModal > div,
#memberModal > div,
#associateModal > div,
#debugModal > div,
#assignStoreModal > div,
#orgAttachStoreModal > div,
#pwdModal > div,
#permModal > div,
#activityModal > div {
	background: linear-gradient(180deg, #16243a 0%, #121c2f 100%) !important;
	color: var(--text) !important;
	border: 1px solid #314766 !important;
	border-radius: 16px !important;
	box-shadow: 0 22px 60px rgba(2, 7, 17, 0.52) !important;
	padding: 18px !important;
}

#rechargeModal h3,
#decrementModal h3,
#memberModal h3,
#associateModal h3,
#debugModal h3,
#assignStoreModal h3,
#orgAttachStoreModal h3,
#pwdModal h3,
#permModal h3,
#activityModal h3 {
	color: #eef4ff;
	font-size: 1.5rem;
	margin-bottom: 12px;
}

#rechargeModal label,
#decrementModal label,
#memberModal label,
#associateModal label,
#debugModal label,
#assignStoreModal label,
#orgAttachStoreModal label,
#pwdModal label,
#permModal label,
#activityModal label,
#rechargeModal small,
#decrementModal small,
#memberModal small,
#associateModal small,
#debugModal small,
#assignStoreModal small,
#orgAttachStoreModal small,
#pwdModal small,
#permModal small,
#activityModal small {
	color: #b8cae4 !important;
}

#assign_store_list,
#orgAttachStoreList,
#perm_grid {
	background: #0f1a2b;
	border-color: #2b3f5e !important;
	border-radius: 12px !important;
	color: var(--text);
}

#perm_tip,
#orgAttachStoreDebug,
#dbg_msg,
#permModal [style*="color:#666"],
#pwdModal [style*="color:#666"],
#memberModal [style*="color:#666"],
#debugModal [style*="color:#666"],
#orgAttachStoreModal [style*="color:#666"],
#activityModal [style*="color:#666"] {
	color: var(--muted) !important;
}

#perm_grid > div,
#assign_store_list > div,
#orgAttachStoreList > div {
	color: var(--text);
}

[id$="Modal"] input[type="checkbox"] {
	accent-color: var(--primary);
}

#activityModal .timeline-meta {
	display: flex;
	justify-content: space-between;
	gap: 12px;
	align-items: center;
	flex-wrap: wrap;
	margin-bottom: 10px;
	padding: 10px 12px;
	border: 1px solid #2d4466;
	border-radius: 12px;
	background: rgba(9, 16, 28, 0.72);
	color: #b7c9e6;
	font-size: 13px;
}

#activityTimeline {
	max-height: 62vh;
	overflow: auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding-right: 4px;
}

.timeline-item {
	border: 1px solid #2a4060;
	border-radius: 14px;
	background: linear-gradient(180deg, rgba(10, 18, 32, 0.94) 0%, rgba(8, 14, 26, 0.88) 100%);
	padding: 12px 14px;
	box-shadow: 0 14px 30px rgba(2, 7, 17, 0.22);
}

.timeline-item-head {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 12px;
	margin-bottom: 6px;
}

.timeline-item-title {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 700;
	color: #f3f7ff;
}

.timeline-item-time {
	color: #8ca5c7;
	font-size: 12px;
	white-space: nowrap;
}

.timeline-item-detail {
	color: #ccdaef;
	line-height: 1.6;
	font-size: 13px;
}

.timeline-item-meta {
	margin-top: 6px;
	color: #7f95b3;
	font-size: 12px;
}

.timeline-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 2px 8px;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: .02em;
	border: 1px solid transparent;
}

.timeline-badge.info {
	background: rgba(37, 99, 235, 0.18);
	border-color: rgba(96, 165, 250, 0.35);
	color: #9cc7ff;
}

.timeline-badge.warning {
	background: rgba(245, 158, 11, 0.16);
	border-color: rgba(251, 191, 36, 0.34);
	color: #ffd27d;
}

.timeline-empty {
	padding: 20px 14px;
	border: 1px dashed #355071;
	border-radius: 14px;
	color: #91a8c8;
	text-align: center;
	background: rgba(9, 16, 28, 0.55);
}

.workbench-header {
	margin-bottom: 10px;
	padding: 14px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	background: linear-gradient(145deg, #182840 0%, #132238 100%);
	border: 1px solid #2e4263;
	border-radius: 14px;
}

.store-mini-stats {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.store-mini-stat {
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 6px 10px;
	background: #0f1a2b;
	display: flex;
	flex-direction: column;
	min-width: 92px;
	box-shadow: var(--soft-shadow);
}

.store-mini-stat .k {
	font-size: 12px;
	color: #9ab0ce;
}

.store-mini-stat .v {
	font-size: 15px;
	font-weight: 700;
	color: #e4ecf8;
}

.store-workbench-layout {
	display: grid;
	grid-template-columns: 280px 1fr;
	gap: 14px;
	align-items: start;
}

.store-rail {
	padding: 12px;
	position: sticky;
	top: 12px;
	max-height: calc(100vh - 120px);
	overflow: auto;
	border-radius: 14px;
	box-shadow: var(--soft-shadow);
}

.store-rail-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 8px;
}

.store-rail input {
	width: 100%;
	margin-bottom: 8px;
}

.store-quick-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.store-quick-item {
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 8px;
	background: #101a2a;
	box-shadow: var(--soft-shadow);
	transition: transform .15s ease, border-color .15s ease;
}

.store-quick-item:hover {
	transform: translateY(-1px);
	border-color: #b6d0ef;
}

.store-quick-item .title {
	font-size: 13px;
	font-weight: 600;
	color: #d8e5f8;
	margin-bottom: 2px;
}

.store-quick-item .meta {
	font-size: 12px;
	color: #97abc8;
	margin-bottom: 6px;
	word-break: break-all;
}

.store-quick-item .ops {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
}

.store-quick-item .ops button,
#storeInfo button,
#storeDevicesPanel button,
#deviceTable button,
#staffTable button,
#rolePerms button,
#tools button,
.signin .actions button {
	background: linear-gradient(180deg, #1a2a43 0%, #142238 100%);
	color: #dce9fb;
	border-color: #355075;
}

.store-quick-item .ops button:hover,
#storeInfo button:hover,
#storeDevicesPanel button:hover,
#deviceTable button:hover,
#staffTable button:hover,
#rolePerms button:hover,
#tools button:hover,
.signin .actions button:hover {
	background: linear-gradient(180deg, #213553 0%, #192b45 100%);
}

.store-pane-tabs {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin-bottom: 10px;
	padding: 10px;
	background: #101a2b;
	border: 1px solid #2b3f5e;
	border-radius: 12px;
}

.store-pane-tabs button {
	background: #132238;
	color: #b9cdea;
	border: 1px solid #35517a;
}

.store-pane-tabs button.active {
	background: linear-gradient(180deg, #4ea1ff 0%, #2f81de 100%);
	color: #fff;
	border-color: var(--primary);
}

.signin .actions .link {
	background: transparent;
	border-color: transparent;
	box-shadow: none;
	color: var(--primary);
}

.signin .actions .link:hover {
	background: rgba(78,161,255,0.10);
	border-color: rgba(78,161,255,0.18);
	transform: none;
}

.store-pane {
	display: none;
}

.store-pane.active {
	display: block;
	background: #0f1a2b;
	border: 1px solid #2b3f5e;
	border-radius: 14px;
	padding: 12px;
	box-shadow: var(--soft-shadow);
}

.store-main {
	min-width: 0;
}

.card {
	background: #121c2f;
	border: 1px solid var(--border);
	border-radius: 14px;
	box-shadow: var(--soft-shadow);
}

.muted {
	color: var(--muted);
}

#storeInfo table,
#storeDevicesPanel table {
	margin-top: 0;
	border-radius: 10px;
	overflow: hidden;
}

/* Modal and inline block dark adaptation */
[style*="background:#fff"] {
	color: var(--text);
}

[style*="background:#fafafa"],
[style*="background:#f7f7f7"] {
	background: #101a2b !important;
	border-color: #2b3f5e !important;
	color: var(--text) !important;
}

[style*="border:1px solid #eee"],
[style*="border:1px solid #ddd"] {
	border-color: #2b3f5e !important;
}

[style*="color:#666"],
[style*="color:#333"] {
	color: var(--muted) !important;
}

[style*="background:#fff3e0"] {
	background: rgba(255, 170, 60, 0.16) !important;
	color: #ffbf6b !important;
}

[style*="background:#e6fffa"] {
	background: rgba(62, 189, 116, 0.14) !important;
	color: #7ee0a3 !important;
}

[style*="background:#fff7ed"] {
	background: rgba(255, 145, 77, 0.14) !important;
	color: #ffb47e !important;
}

@media (max-width: 980px) {
	.workbench-header {
		flex-direction: column;
		align-items: flex-start;
	}

	.store-workbench-layout {
		grid-template-columns: 1fr;
	}

	.store-rail {
		position: static;
		max-height: none;
	}
}
