/* ==========================================================================
   Library Management System - styles (works fully offline, no CDN)
   ========================================================================== */

:root {
  --ink: #1f2a24;
  --ink-soft: #4b5a52;
  --muted: #7d8a83;
  --paper: #f6f3ec;
  --card: #ffffff;
  --line: #e4ded1;
  --green: #2f6b4f;
  --green-dark: #224f3a;
  --green-tint: #e5f0e9;
  --red: #b3392f;
  --red-tint: #fbe9e7;
  --amber: #a86a12;
  --amber-tint: #fdf1dc;
  --blue: #2c5d8a;
  --blue-tint: #e6eef6;
  --sidebar: #1d2b24;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 42, 36, .06), 0 4px 14px rgba(31, 42, 36, .05);
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--serif); font-weight: normal; margin: 0 0 .5em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; font-family: var(--sans); font-weight: 600; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--sidebar); color: #d7e2dc;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 16px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand .logo { font-family: var(--serif); font-size: 21px; color: #fff; line-height: 1.2; }
.brand small { color: #93a89c; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }
.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; margin: 1px 0;
  border-radius: 8px; color: #cfdcd5; font-size: 14.5px;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--green); color: #fff; }
.nav .ico { width: 20px; text-align: center; font-size: 15px; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7f978a; padding: 14px 12px 4px; }
.nav .pill { margin-left: auto; background: var(--red); color: #fff; font-size: 11.5px; border-radius: 20px; padding: 1px 8px; font-weight: 600; }
.sidebar .user { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; color: #93a89c; }
.sidebar .user form { display: inline; }
.sidebar .user button { background: none; border: 0; color: #e7b4ae; cursor: pointer; padding: 0; font: inherit; }

.main { flex: 1; min-width: 0; padding: 28px 34px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Alert banner and messages ---------- */
.alert-banner {
  display: flex; align-items: center; gap: 14px; background: var(--red); color: #fff;
  padding: 12px 18px; border-radius: var(--radius); margin-bottom: 18px; flex-wrap: wrap;
  animation: pulse 2.4s ease-in-out infinite;
}
.alert-banner strong { font-size: 15.5px; }
.alert-banner .grow { flex: 1; }
.alert-banner a, .alert-banner button {
  color: var(--red); background: #fff; border: 0; padding: 6px 12px; border-radius: 6px;
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.alert-banner .ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(179,57,47,.35); } 50% { box-shadow: 0 0 0 6px rgba(179,57,47,0); } }

.messages { list-style: none; padding: 0; margin: 0 0 18px; }
.messages li { padding: 11px 16px; border-radius: 8px; margin-bottom: 8px; border: 1px solid; }
.messages .success { background: var(--green-tint); border-color: #bcd8c7; color: var(--green-dark); }
.messages .error { background: var(--red-tint); border-color: #efc2bd; color: #8a2a22; }
.messages .warning { background: var(--amber-tint); border-color: #eed3a6; color: #7a4c0b; }
.messages .info { background: var(--blue-tint); border-color: #c4d5e6; color: #234a6e; }

/* ---------- Cards and stats ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 18px; }
.grid-2 > .card, .grid-3-1 > .card, .scan-layout > .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.card-head h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .stat-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-family: var(--serif); font-size: 32px; line-height: 1.15; margin-top: 4px; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.stat.danger { border-color: #efc2bd; background: var(--red-tint); }
.stat.danger .value { color: var(--red); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: #faf8f3; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { background: #fff; border-color: #e3b1ab; color: var(--red); }
.btn.danger:hover { background: var(--red-tint); }
.btn.big { padding: 13px 22px; font-size: 16px; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 5px; color: var(--ink-soft); }
.field .help { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.field .errors { color: var(--red); font-size: 13px; margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid #d6cfbf; border-radius: 8px; font: inherit;
  background: #fff; color: var(--ink);
}
.input:focus { outline: 2px solid #9fc8b2; border-color: var(--green); }
.input.scan { font-size: 20px; padding: 14px 16px; font-family: Consolas, monospace; letter-spacing: .03em; }
.check { width: 18px; height: 18px; vertical-align: middle; }
.form-errors { background: var(--red-tint); color: #8a2a22; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .input { width: auto; }
.toolbar .search { flex: 1; min-width: 220px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 7px 14px; border-radius: 20px; color: var(--ink-soft); border: 1px solid var(--line); background: #fff; font-size: 13.5px; }
.tabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs a:hover { text-decoration: none; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid #efeae0; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.row-overdue td { background: #fdf3f1; }
.mono { font-family: Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--green-tint); color: var(--green-dark); }
.badge.red { background: var(--red-tint); color: var(--red); }
.badge.amber { background: var(--amber-tint); color: var(--amber); }
.badge.gray { background: #eeebe4; color: var(--ink-soft); }
.badge.blue { background: var(--blue-tint); color: var(--blue); }

/* ---------- Book grid ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 18px; }
.book-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; color: var(--ink); }
.book-card:hover { text-decoration: none; transform: translateY(-2px); transition: transform .15s; }
.book-card .cover { aspect-ratio: 3 / 4; background: #ece6d8; position: relative; }
.book-card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-card .cover .badge { position: absolute; top: 8px; right: 8px; }
.book-card .info { padding: 10px 12px 12px; }
.book-card .title { font-weight: 600; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card .author { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.no-cover {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 14px; background: linear-gradient(160deg, #2f6b4f, #1d2b24); color: #f1ead8;
  font-family: var(--serif); font-size: 15px; line-height: 1.25;
}
.no-cover small { font-family: var(--sans); font-size: 11px; opacity: .7; margin-top: 8px; }
.thumb { width: 42px; height: 56px; border-radius: 4px; object-fit: cover; background: #ece6d8; display: block; }
.thumb.no-cover { font-size: 9px; padding: 3px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--green-tint); color: var(--green-dark); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; }
.avatar.lg { width: 96px; height: 96px; font-size: 32px; }

/* ---------- Book detail ---------- */
.detail { display: grid; grid-template-columns: 260px 1fr; gap: 26px; align-items: start; }
.detail .cover-lg { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); aspect-ratio: 3 / 4; background: #ece6d8; box-shadow: var(--shadow); }
.detail .cover-lg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.barcode-box { background: #fff; border: 1px dashed #cfc7b5; border-radius: 8px; padding: 10px; text-align: center; }
.barcode-box img { height: 70px; }

/* ---------- Issue / return scan panels ---------- */
.scan-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.preview { min-height: 140px; border: 1px dashed #cfc7b5; border-radius: var(--radius); padding: 14px; display: flex; gap: 14px; align-items: center; background: #fdfcf9; }
.preview.ok { border: 1px solid #bcd8c7; background: var(--green-tint); }
.preview.bad { border: 1px solid #efc2bd; background: var(--red-tint); }
.preview .p-img { width: 80px; height: 106px; flex-shrink: 0; border-radius: 6px; overflow: hidden; background: #ece6d8; }
.preview .p-img img { width: 100%; height: 100%; object-fit: cover; }
.preview .p-img.round { width: 80px; height: 80px; border-radius: 50%; }
.preview .p-title { font-weight: 600; font-size: 16px; }
.step-num { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; align-items: center; justify-content: center; font-size: 13px; margin-right: 6px; }

.loan-match { display: flex; gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; flex-wrap: wrap; }
.loan-match .grow { flex: 1; min-width: 200px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 20% 20%, #2f6b4f, #1d2b24 70%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card p { text-align: center; color: var(--muted); margin-top: 0; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; }

/* ---------- Member ID card ---------- */
.id-card {
  width: 340px; height: 214px; border-radius: 12px; overflow: hidden; background: #fff;
  border: 1px solid #d6cfbf; box-shadow: var(--shadow); display: flex; flex-direction: column; font-size: 12px;
}
.id-card .top { background: var(--sidebar); color: #fff; padding: 8px 14px; font-family: var(--serif); font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.id-card .top small { font-family: var(--sans); font-size: 10px; opacity: .7; letter-spacing: .08em; }
.id-card .body { display: flex; gap: 12px; padding: 10px 14px 0; flex: 1; }
.id-card .photo { width: 70px; height: 86px; border-radius: 6px; object-fit: cover; background: var(--green-tint); display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--green-dark); flex-shrink: 0; }
.id-card .name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.id-card .mid { font-family: Consolas, monospace; font-size: 15px; color: var(--green-dark); margin: 3px 0; }
.id-card .bc { text-align: center; padding: 0 10px 6px; }
.id-card .bc img { height: 54px; }

/* ---------- Print labels ---------- */
.labels { display: grid; grid-template-columns: repeat(auto-fill, 230px); gap: 10px; }
.label { border: 1px dashed #bbb; padding: 8px 10px; background: #fff; text-align: center; font-size: 11px; page-break-inside: avoid; }
.label .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label > img { height: 58px; }

.print-only { display: none; }
@media print {
  .sidebar, .no-print, .alert-banner, .messages { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
  .print-only { display: block; }
  .id-card, .label { box-shadow: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { display: flex; flex-wrap: wrap; }
  .nav .section { display: none; }
  .main { padding: 18px 16px 40px; }
  .grid-2, .grid-3-1, .scan-layout, .form-grid, .detail { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px 1fr; }
}

/* ---------- Institute logo ---------- */
.brand { display: block; text-align: center; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 132px; height: auto; display: block; margin: 0 auto 10px; background: #fff; border-radius: 16px; padding: 8px 10px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.login-logo { width: 150px; height: auto; display: block; margin: 0 auto 14px; }
.id-card .top-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; line-height: 1.15; }
.id-card .top small { flex-shrink: 0; white-space: nowrap; margin-left: 8px; }
.id-card .top-name img { width: 30px; height: auto; flex-shrink: 0; }
.label-head { display: flex; align-items: center; justify-content: center; gap: 5px; }
.label-head img { width: 20px; height: auto; flex-shrink: 0; }
.label-head span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Rack and class cards ---------- */
.rack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; align-content: start; }
.rack-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; color: var(--ink); display: flex; flex-direction: column; gap: 6px; border-top: 4px solid var(--green); }
.rack-card:hover { text-decoration: none; transform: translateY(-2px); transition: transform .15s; }
.rack-name { font-family: var(--serif); font-size: 22px; line-height: 1.2; }
.rack-counts { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink-soft); }
.errors { color: var(--red); }

/* ---------- Money ---------- */
td.mono, th.mono, .stat .value { white-space: nowrap; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }

/* ---------- Powered by snova.lk ---------- */
.powered-by { margin-top: 36px; padding-top: 14px; border-top: 1px solid var(--line); text-align: center; font-size: 12.5px; color: var(--muted); }
.powered-by a { color: var(--green); }
.login-wrap { flex-direction: column; gap: 16px; }
.login-powered .powered-by { border: 0; margin: 0; padding: 0; color: #cfdcd5; }
.login-powered .powered-by a { color: #fff; }
@media print { .powered-by { margin-top: 16px; font-size: 10px; color: #666; } .powered-by a { color: #333; text-decoration: none; } }
