/* =====================================================================================================================
   Slakt vs Teknik innebandy – mörkt sporttema, mobilen först
   ===================================================================================================================== */

:root {
	--bg:          #0d0f13;
	--bg-2:        #12151b;
	--surface:     #181c24;
	--surface-2:   #20252f;
	--border:      #2b313d;
	--text:        #eceef2;
	--muted:       #98a1b1;
	--accent:      #ffb400;
	--accent-dark: #d99600;
	--red:         #ef4444;
	--green:       #22c55e;
	--blue:        #3b82f6;
	--radius:      14px;
	--shadow:      0 10px 30px rgba(0, 0, 0, .35);
	--accent-text: var(--accent);   /* accentfärg för text (mörkare i ljust tema) */
	--line:        rgba(255, 255, 255, .05);
	--stripe:      rgba(255, 255, 255, .02);
	color-scheme:  dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	min-height: 100vh;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 16px;
	line-height: 1.45;
	color: var(--text);
	background:
		radial-gradient(1200px 500px at 15% -10%, rgba(239, 68, 68, .16), transparent 60%),
		radial-gradient(1000px 500px at 100% 0%, rgba(59, 130, 246, .14), transparent 60%),
		var(--bg);
	background-attachment: fixed;
}

a { color: var(--accent-text); text-decoration: none; font-weight: 600; }
a:hover { color: #ffd166; }

h1, h2, h3, h4, h5 { margin: 0 0 .6em; line-height: 1.2; }
h2 { font-size: 1.15rem; letter-spacing: .02em; }
h3 { font-size: 1rem; color: var(--accent-text); }

p { margin: 0 0 .8em; }

/* ------------------------------------------------------------------ Sidhuvud */
.site-header {
	padding: 18px 14px 6px;
	text-align: center;
}

#logo img {
	width: 100%;
	max-width: 260px;
	height: auto;
	border-radius: 12px;
	box-shadow: var(--shadow);
	display: block;
	margin: 0 auto;
}

.site-title {
	margin: 14px 0 12px;
	font-size: 1.3rem;
	font-weight: 800;
	text-transform: uppercase;
	letter-spacing: .04em;
}

.site-title::after {
	content: "";
	display: block;
	width: 64px;
	height: 3px;
	margin: 10px auto 0;
	border-radius: 2px;
	background: linear-gradient(90deg, var(--red), var(--accent), var(--blue));
}

/* ------------------------------------------------------------------ Meny */
.menu ul {
	list-style: none;
	margin: 0 auto;
	padding: 4px;
	display: flex;
	gap: 6px;
	overflow-x: auto;
	scrollbar-width: none;
	justify-content: flex-start;
	max-width: 960px;
}
.menu ul::-webkit-scrollbar { display: none; }

.menu li { flex: 0 0 auto; }

.menu a {
	display: block;
	padding: 8px 14px;
	border-radius: 999px;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	font-size: .9rem;
	white-space: nowrap;
}
.menu a:hover { border-color: var(--accent); color: var(--accent-text); }
.menu a.active { background: var(--accent); border-color: var(--accent); color: #111; }

.menu2 ul { margin-bottom: 14px; }
.menu2 a { background: var(--surface-2); }

@media (min-width: 720px) {
	.menu ul { justify-content: center; flex-wrap: wrap; }
}

/* ------------------------------------------------------------------ Innehåll */
#main {
	max-width: 960px;
	margin: 0 auto;
	padding: 12px 12px 30px;
}

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px;
	margin-bottom: 14px;
	box-shadow: var(--shadow);
}

.card.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }

.card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-wrap: wrap;
	margin-bottom: 10px;
}
.card-head h2 { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

.notice {
	padding: 10px 14px;
	border-radius: 10px;
	background: rgba(255, 180, 0, .12);
	border: 1px solid rgba(255, 180, 0, .35);
	color: #ffd166;
	margin-bottom: 14px;
}
.notice.error { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); color: #fca5a5; }

/* ------------------------------------------------------------------ Formulär */
input, select, textarea, button {
	font: inherit;
	color: var(--text);
}

input[type=text], input[type=password], input[type=email], input[type=tel], input[type=number], select, textarea {
	width: 100%;
	padding: 10px 12px;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: var(--bg-2);
	outline: none;
	min-height: 44px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 180, 0, .2); }

select {
	appearance: none;
	background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
	background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
	padding-right: 34px;
}

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.form-grid { display: grid; gap: 0 14px; }
@media (min-width: 560px) { .form-grid.two { grid-template-columns: 1fr 1fr; } }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

.btn, button, input[type=submit], input[type=button] {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: 44px;
	padding: 10px 18px;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: var(--surface-2);
	color: var(--text);
	font-weight: 700;
	cursor: pointer;
	text-decoration: none;
	transition: transform .05s, background .15s, border-color .15s;
	width: auto;
}
.btn:hover, button:hover, input[type=submit]:hover, input[type=button]:hover { border-color: var(--accent); color: var(--text); }
.btn:active, button:active { transform: translateY(1px); }

.btn.primary, button.primary, input[type=submit].primary { background: var(--accent); border-color: var(--accent); color: #111; }
.btn.primary:hover, button.primary:hover { background: #ffc633; color: #111; }
.btn.danger, button.danger { background: transparent; border-color: rgba(239, 68, 68, .5); color: #fca5a5; }
.btn.danger:hover { background: rgba(239, 68, 68, .15); }
.btn.ghost, button.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }

/* ------------------------------------------------------------------ Närvaro */
.playdate-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 14px;
}
.playdate-bar label { margin: 0; flex: 1; max-width: 220px; }
.playdate-bar .big-date { font-size: 1.6rem; font-weight: 800; color: var(--accent-text); line-height: 1; }

.presence-grid { display: grid; gap: 10px; }
@media (min-width: 720px) { .presence-grid { grid-template-columns: repeat(3, 1fr); } }

.pcol {
	background: var(--bg-2);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 12px;
	border-top: 4px solid var(--muted);
}
.pcol.playing     { border-top-color: var(--green); }
.pcol.not-playing { border-top-color: var(--red); }
.pcol.not-reported{ border-top-color: var(--muted); }

.pcol h3 {
	display: flex;
	justify-content: space-between;
	align-items: center;
	color: var(--text);
	font-size: .95rem;
	text-transform: uppercase;
	letter-spacing: .05em;
	margin-bottom: 8px;
}
.count {
	min-width: 32px;
	padding: 2px 10px;
	border-radius: 999px;
	background: var(--surface-2);
	font-size: .95rem;
	text-align: center;
}
.playing .count     { background: rgba(34, 197, 94, .18); color: #86efac; }
.not-playing .count { background: rgba(239, 68, 68, .18); color: #fca5a5; }

.pcol ul { list-style: none; margin: 0; padding: 0; }
.pcol li {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 2px;
	border-bottom: 1px solid var(--line);
	font-size: .95rem;
}
.pcol li:last-child { border-bottom: 0; }
.pcol li .games { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.pcol .empty { color: var(--muted); font-style: italic; font-size: .9rem; }

.vote-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.vote-buttons .btn { min-height: 56px; font-size: 1.05rem; }
.vote-buttons .btn.yes { background: var(--green); border-color: var(--green); color: #07210f; }
.vote-buttons .btn.no  { background: var(--red); border-color: var(--red); color: #fff; }
.vote-buttons .btn.reset { grid-column: 1 / -1; min-height: 40px; font-size: .9rem; background: transparent; }

/* Meddelanden (lagras som HTML i databasen) */
.msg_date { display: block; color: var(--muted); font-size: .8rem; margin-top: 12px; }
.msg_body {
	display: block;
	background: var(--bg-2);
	border: 1px solid var(--border);
	border-left: 4px solid var(--accent);
	border-radius: 10px;
	padding: 10px 12px;
	margin-top: 4px;
	overflow-wrap: anywhere;
}
.msg_body b { color: var(--accent-text); }

/* Dialog för nytt meddelande */
dialog {
	width: min(560px, calc(100vw - 24px));
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 18px;
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(2px); }

/* ------------------------------------------------------------------ Tabeller */
.table-wrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border: 1px solid var(--border);
	border-radius: 12px;
	margin: 10px 0 16px;
}

table {
	width: 100%;
	border-collapse: collapse;
	font-size: .88rem;
}

th, td {
	padding: 9px 10px;
	text-align: left;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
	white-space: nowrap;
}

th, tr.header td {
	position: sticky;
	top: 0;
	background: var(--surface-2);
	color: var(--muted);
	font-size: .75rem;
	text-transform: uppercase;
	letter-spacing: .05em;
	font-weight: 700;
}
th[onclick] { cursor: pointer; user-select: none; }
th[onclick]::after { content: " ⇅"; opacity: .45; }
th[onclick]:hover { color: var(--accent-text); }

tbody tr:nth-child(even) td, table tr:nth-child(even) td { background: var(--stripe); }
table tr:hover td { background: rgba(255, 180, 0, .06); }
td.num, th.num { text-align: right; }
td.icon { text-align: center; }
td.icon a { font-size: 1.05rem; padding: 4px 6px; }

td input[type=number] { width: 80px; min-height: 38px; padding: 6px 8px; }

details.card summary { cursor: pointer; font-weight: 700; color: var(--accent-text); }
details.card[open] summary { margin-bottom: 10px; }

/* ------------------------------------------------------------------ Topplistor */
.toplist { display: grid; gap: 10px; }
@media (min-width: 640px) { .toplist { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .toplist { grid-template-columns: repeat(3, 1fr); } }

.top-card {
	background: var(--bg-2);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 12px;
}
.top-card h3 { margin-bottom: 8px; }
.top-row { display: flex; gap: 10px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--line); }
.top-row:last-child { border-bottom: 0; }
.top-row .medal { width: 24px; flex: 0 0 24px; }
.top-row .score { font-weight: 800; min-width: 48px; color: var(--text); }
.top-row .who { color: var(--muted); font-size: .9rem; }

/* ------------------------------------------------------------------ Kalender */
#my_calendar, #match_my_calendar { max-width: 460px; margin: 0 auto; }
#my_calendar p, #match_my_calendar p { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 1.1rem; }
#my_calendar p a, #match_my_calendar p a {
	display: inline-flex; align-items: center; justify-content: center;
	width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 1.3rem;
}
#my_calendar table, #match_my_calendar table { table-layout: fixed; border: 0; }
#my_calendar td, #match_my_calendar td {
	text-align: center;
	padding: 0;
	height: 46px;
	border: 2px solid var(--surface);
	border-radius: 10px;
	background: var(--bg-2);
	white-space: normal;
}
#my_calendar tr.header td, #match_my_calendar tr.header td { background: transparent; height: 30px; position: static; }
#my_calendar td.selectable, #match_my_calendar td.selectable { cursor: pointer; font-weight: 600; }
#my_calendar td.selectable:hover, #match_my_calendar td.selectable:hover { background: var(--surface-2); outline: 2px solid var(--accent); }
#my_calendar td.cssPlayDay, #match_my_calendar td.cssPlayDay { background: var(--accent) !important; color: #111; font-weight: 800; }

/* ------------------------------------------------------------------ Sidfot och status */
.status {
	text-align: center;
	color: var(--muted);
	font-size: .8rem;
	margin: 6px 0 0;
}
.status .chip {
	display: inline-block;
	margin: 3px;
	padding: 3px 10px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: var(--surface);
}
.status .chip.on { border-color: rgba(34, 197, 94, .5); color: #86efac; }

/* ------------------------------------------------------------------ Mobilanpassning av tabeller */
#PlayerTable tr > :first-child {
	position: sticky;
	left: 0;
	z-index: 1;
	background: var(--surface);
	box-shadow: 1px 0 0 var(--border);
}
#PlayerTable tr.header > :first-child { z-index: 2; background: var(--surface-2); }

@media (max-width: 719px) {
	.hide-sm { display: none; }
	th, td { padding: 8px 8px; }
	td input[type=number] { width: 64px; }
}

#edit_status .playdate-bar { margin-bottom: 6px; }

/* Meddelanden med knappar för ändra/ta bort */
.msg-item { margin-bottom: 6px; }
.msg-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.msg-actions .btn { min-height: 30px; padding: 4px 10px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.msg-actions .btn:hover { color: var(--text); }

/* Captcha */
.captcha-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; flex-wrap: wrap; }
.captcha-row img { border-radius: 8px; border: 1px solid var(--border); background: #eef0f3; }
input[name=captcha] { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; }

/* ------------------------------------------------------------------ Byt tema (mörkt/ljust) */
.site-header { position: relative; }
.theme-toggle {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 42px;
	height: 42px;
	min-height: 0;
	padding: 0;
	border-radius: 999px;
	font-size: 1.15rem;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	box-shadow: var(--shadow);
	cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle .when-light { display: none; }
[data-theme="light"] .theme-toggle .when-light { display: inline; }
[data-theme="light"] .theme-toggle .when-dark  { display: none; }

/* ------------------------------------------------------------------ Ljust tema */
[data-theme="light"] {
	color-scheme: light;
	--bg:          #f3f4f7;
	--bg-2:        #f7f8fa;
	--surface:     #ffffff;
	--surface-2:   #eef0f4;
	--border:      #d7dbe3;
	--text:        #161a22;
	--muted:       #5d6676;
	--accent:      #f0a500;
	--accent-dark: #c98a00;
	--accent-text: #9a5c00;
	--red:         #dc2626;
	--green:       #16a34a;
	--blue:        #2563eb;
	--shadow:      0 6px 18px rgba(20, 30, 50, .10);
	--line:        rgba(0, 0, 0, .07);
	--stripe:      rgba(0, 0, 0, .025);
}
[data-theme="light"] body {
	background:
		radial-gradient(1200px 500px at 15% -10%, rgba(239, 68, 68, .10), transparent 60%),
		radial-gradient(1000px 500px at 100% 0%, rgba(59, 130, 246, .10), transparent 60%),
		var(--bg);
	background-attachment: fixed;
}
[data-theme="light"] a:hover { color: #7a4900; }
[data-theme="light"] .notice { background: rgba(240, 165, 0, .12); border-color: rgba(240, 165, 0, .45); color: #7a4900; }
[data-theme="light"] .notice.error { background: rgba(220, 38, 38, .08); border-color: rgba(220, 38, 38, .35); color: #b91c1c; }
[data-theme="light"] .btn.danger, [data-theme="light"] button.danger { color: #b91c1c; border-color: rgba(220, 38, 38, .45); }
[data-theme="light"] .btn.danger:hover { background: rgba(220, 38, 38, .08); }
[data-theme="light"] .btn.primary:hover, [data-theme="light"] button.primary:hover { background: #ffb81f; }
[data-theme="light"] .vote-buttons .btn.yes { color: #fff; }
[data-theme="light"] .playing .count     { background: rgba(22, 163, 74, .14); color: #15803d; }
[data-theme="light"] .not-playing .count { background: rgba(220, 38, 38, .12); color: #b91c1c; }
[data-theme="light"] .status .chip.on { border-color: rgba(22, 163, 74, .5); color: #15803d; }
[data-theme="light"] table tr:hover td { background: rgba(240, 165, 0, .08); }
[data-theme="light"] dialog::backdrop { background: rgba(20, 25, 35, .45); }
[data-theme="light"] .captcha-row img { background: #ffffff; }
