@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@600;700&display=swap');

:root {
  /* ICAI Managerial Palette */
  --brand-primary: #7a2e2e;
  --brand-gold: #b8892e;
  --brand-gold-dark: #9f7425;
  --brand-cream: #faf6ee;
  --brand-surface: #fffdf8;
  --brand-surface2: #f4ede0;
  --brand-border: #e7d8c4;
  --brand-ink: #2b241e;
  --brand-muted: #6f6154;
  --brand-dim: #86786a;

  --bg: var(--brand-cream); 
  --surface: var(--brand-surface); 
  --surface2: var(--brand-surface2); 
  --border: var(--brand-border);
  
  --google-blue: var(--brand-primary);
  --google-red: #b24b3a;
  --google-yellow: #e6c98a;
  --google-green: var(--brand-gold);
  --google-pink: #c07a7a;

  --accent: var(--google-blue);
  --accent-soft: rgba(122, 46, 46, 0.1);
  
  --text: var(--brand-ink); 
  --text-muted: var(--brand-muted); 
  --text-dim: var(--brand-dim);
  
  --radius: 8px; 
  --shadow: 0 1px 2px 0 rgba(70,55,40,0.2), 0 1px 3px 1px rgba(70,55,40,0.12);
  --shadow-hover: 0 1px 3px 0 rgba(70,55,40,0.24), 0 4px 8px 3px rgba(70,55,40,0.16);
}

*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
body{font-family:'Inter', sans-serif;background:var(--bg);color:var(--text);min-height:100vh;overflow-x:hidden}

/* ── TOP BAR ─────────────────────────── */
#topbar{display:flex;align-items:center;justify-content:space-between;padding:12px 24px;
  background:var(--surface);border-bottom:1px solid var(--border);
  position:sticky;top:0;z-index:50;box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05)}
#topbar .brand{display:flex;align-items:center;gap:12px}
#topbar .brand-icon{font-size:24px}
#topbar .brand-name{font-family:'Inter', sans-serif;font-size:18px;font-weight:600;color:var(--text)}
#topbar .brand-sub{font-size:12px;color:var(--text-muted);font-weight:400;margin-top:2px}
#topbar .back-btn{text-decoration:none;font-size:12px;padding:6px 12px;margin-right:8px}
.topbar-right{display:flex;align-items:center;gap:12px}

/* ── BUTTONS (Google Colors) ─────────── */
.btn{display:inline-flex;align-items:center;gap:8px;padding:10px 20px;border-radius:24px;
  border:1px solid var(--border);cursor:pointer;font-family:'Inter',sans-serif;font-size:14px;font-weight:500;transition:all .2s;
  background:var(--surface);color:var(--text)}
.btn:hover{background:var(--surface2);box-shadow: 0 1px 2px rgba(60,64,67,0.3)}

.btn-primary{background:var(--google-blue);color:#fff;border:none}
.btn-primary:hover{background:#357ae8;box-shadow: 0 1px 3px rgba(66,133,244,0.4)}

.btn-success{background:var(--google-green);color:#fff;border:none}
.btn-success:hover{background:#2d8e47;box-shadow: 0 1px 3px rgba(52,168,83,0.4)}

.btn-danger{background:var(--google-red);color:#fff;border:none}
.btn-danger:hover{background:#d33828}

.btn-warning{background:var(--google-yellow);color:var(--text);border:none}
.btn-warning:hover{background:#f4b400}

.btn-pink{background:var(--google-pink);color:#fff;border:none}
.btn-pink:hover{background:#ec407a}

.btn-ghost{background:transparent;color:var(--text-muted);border:1px solid var(--border)}
.btn-ghost:hover{background:var(--surface2);color:var(--text)}

.btn-sm{padding:6px 14px;font-size:12px}
.btn:disabled{opacity:.4;cursor:not-allowed;transform:none!important;box-shadow:none!important}

/* ── LAYOUT ─────────────────────────── */
#app{display:flex;height:calc(100vh - 61px)}
#sidebar{width:340px;flex-shrink:0;background:var(--surface);border-right:1px solid var(--border);
  display:flex;flex-direction:column;overflow:hidden}
#main{flex:1;overflow-y:auto;padding:32px 40px;display:flex;flex-direction:column;gap:32px;background:var(--bg)}

/* ── SIDEBAR ─────────────────────────── */
.sidebar-section{padding:24px;border-bottom:1px solid var(--border)}
.sidebar-section h3{font-size:12px;font-weight:600;color:var(--text-muted);text-transform:uppercase;letter-spacing:.05em;margin-bottom:16px}
.filter-group{display:flex;flex-direction:column;gap:8px;margin-bottom:12px}
.filter-group label{font-size:12px;color:var(--text-muted);font-weight:600}
select,input[type=text],input[type=number]{width:100%;padding:10px 12px;border-radius:var(--radius);
  background:var(--surface);border:1px solid var(--border);color:var(--text);
  font-family:'Inter',sans-serif;font-size:14px;outline:none;transition:border-color .2s}
select:focus,input[type=text]:focus{border-color:var(--google-blue);box-shadow: inset 0 0 0 1px var(--google-blue)}
.search-input{position:relative}
.search-input input{padding-left:36px}
.search-input .search-icon{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--text-dim);font-size:14px}
.selected-badge{display:inline-flex;align-items:center;justify-content:center;
  background:var(--google-blue);color:#fff;border-radius:20px;font-size:11px;font-weight:700;padding:2px 8px;min-width:24px}

#sidebar-qlist{flex:1;overflow-y:auto;padding:12px;background:var(--bg)}
#sidebar-qlist::-webkit-scrollbar{width:6px}
#sidebar-qlist::-webkit-scrollbar-thumb{background:#bdc1c6;border-radius:6px}

/* ── TABS (Google Style) ────────────── */
.tab-bar{display:flex;padding:0 12px;background:var(--surface);border-bottom:1px solid var(--border)}
.tab-btn{flex:1;padding:12px 4px;border:none;background:transparent;color:var(--text-muted);
  cursor:pointer;font-family:'Inter',sans-serif;font-size:13px;font-weight:500;
  border-bottom:3px solid transparent;transition:all .2s;text-align:center}
.tab-btn:hover{color:var(--text);background:var(--surface2)}
.tab-btn.active{color:var(--google-blue);border-bottom-color:var(--google-blue)}

/* ── Q CARDS ─────────────────────────── */
.q-card{display:flex;align-items:flex-start;gap:12px;padding:16px;border-radius:var(--radius);
  margin-bottom:12px;border:1px solid var(--border);background:var(--surface);cursor:pointer;transition:all .2s;box-shadow:0 1px 2px rgba(60,64,67,0.1)}
.q-card:hover{border-color:var(--google-blue);box-shadow:0 2px 6px rgba(60,64,67,0.15)}
.q-card.selected{border-color:var(--google-blue);background:var(--accent-soft)}

.q-checkbox{width:20px;height:20px;flex-shrink:0;border-radius:4px;border:2px solid #bdc1c6;
  display:flex;align-items:center;justify-content:center;margin-top:2px;background:#fff;transition:all .2s}
.q-card.selected .q-checkbox{background:var(--google-blue);border-color:var(--google-blue)}
.q-card.selected .q-checkbox::after{content:'✓';color:#fff;font-size:12px;font-weight:700}

.q-info{flex:1;min-width:0}
.q-title{font-size:14px;font-weight:500;color:var(--text);line-height:1.5}
.q-meta{display:flex;gap:8px;align-items:center;margin-top:8px;flex-wrap:wrap}
.q-badge{display:inline-block;padding:2px 8px;border-radius:4px;font-size:11px;font-weight:500}
.badge-source{background:#e8f0fe;color:#1a73e8}
.badge-marks{background:#fef7e0;color:#b06000}
.badge-chapter{background:#e6f4ea;color:#137333}

/* ── MAIN CONTENT AREA ──────────────── */
.main-header h2{font-size:24px;font-weight:500;color:var(--text)}
.main-header p{font-size:14px;color:var(--text-muted);margin-top:4px}

.stat-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:20px}
.stat-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:16px 20px 32px 20px;display:flex;flex-direction:column;gap:4px;box-shadow:0 1px 2px rgba(0,0,0,0.05);position:relative}
.stat-card .stat-val{font-size:28px;font-weight:600;color:var(--google-blue)}
.stat-card .stat-label{font-size:11px;color:var(--text-muted);font-weight:600;text-transform:uppercase;letter-spacing:.02em}
.stat-sub{position:absolute;bottom:10px;left:20px;font-size:10px;color:var(--text-dim);font-weight:500;letter-spacing:0.02em}

.chapter-grid{display:flex;flex-wrap:wrap;gap:10px}
.chapter-pill{padding:8px 16px;border-radius:24px;border:1px solid var(--border);font-size:13px;color:var(--text-muted);cursor:pointer;transition:all .2s;background:var(--surface)}
.chapter-pill:hover{background:var(--surface2);border-color:#bdc1c6;color:var(--text)}
.chapter-pill.active{background:var(--google-blue);border-color:var(--google-blue);color:#fff}

.panel{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;box-shadow:0 1px 2px rgba(0,0,0,0.05)}
.panel-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid var(--border);background:#fff}
.panel-header h3{font-size:16px;font-weight:500;color:var(--text)}

.sel-item{display:flex;align-items:center;gap:16px;padding:16px 20px;border-bottom:1px solid var(--border);transition:background .2s}
.sel-item:hover{background:#f8f9fa}
.sel-num{width:32px;height:32px;border-radius:50%;background:#e8f0fe;color:#1a73e8;display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:600;flex-shrink:0}
.sel-info{flex:1;min-width:0}
.sel-info .sel-title{font-size:14px;font-weight:500;color:var(--text)}
.sel-info .sel-sub{font-size:12px;color:var(--text-muted);margin-top:4px}
.sel-remove{width:32px;height:32px;border-radius:50%;background:transparent;border:none;color:var(--text-dim);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:18px;transition:all .2s}
.sel-remove:hover{background:#fde8e8;color:var(--google-red)}

.generate-bar{padding:24px 0;border-top:1px solid var(--border);margin-top:12px;display:flex;flex-direction:column;gap:12px}

/* ── EMPTY STATES ────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}
.empty-icon {
  font-size: 32px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.empty-state p {
  font-size: 13px;
  line-height: 1.5;
}

/* ── MODALS ──────────────────────────── */
.modal-overlay{position:fixed;inset:0;background:rgba(32,33,36,0.6);display:flex;align-items:center;justify-content:center;z-index:100;backdrop-filter:none}
.modal{background:var(--surface);border-radius:12px;width:90%;max-width:560px;padding:32px;box-shadow:0 12px 15px 0 rgba(0,0,0,0.24);animation:modalIn 0.2s cubic-bezier(0,0,0.2,1)}
.modal h2{font-size:22px;font-weight:400;margin-bottom:24px;color:var(--text)}
.modal-grid{display:grid;grid-template-columns:1fr 1fr;gap:20px}
.modal-actions{display:flex;justify-content:flex-end;gap:12px;margin-top:32px}

/* ── PREVIEW PANEL ──────────────────── */
#preview-content{background:#fff;border-radius:0 0 8px 8px}
#preview-content table { border-collapse: collapse; margin: 16px 0; width: 100%; border: 1px solid var(--brand-border); background: var(--google-yellow); }
#preview-content th, #preview-content td { border: 1px solid var(--brand-border); padding: 10px 14px; }
#preview-content th { background: var(--brand-gold); color: #fff; font-weight: 700; text-transform: uppercase; }

/* ── PRINT COMPATIBILITY ────────────── */
.pq-body,.pa-body{overflow-x:hidden;max-width:100%}
.pq-body *,.pa-body *{font-family:'Times New Roman',Times,serif !important;color:#000 !important;background:transparent !important}

@media print{
  html,body{background:#fff}
  body>*:not(#pdf-preview){display:none!important}
  #pdf-preview{display:block!important;position:static!important;padding:0!important}
  .preview-toolbar{display:none!important}
  .preview-page{box-shadow:none!important;margin:0!important;max-width:100%!important;page-break-after:always}
}

/* ── RANDOM TABLE ───────────────────── */
.random-table-wrapper {
  margin-top: 15px;
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.random-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.random-table th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  padding: 12px 10px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  z-index: 10;
}
.random-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.random-table tr:hover { background: #f8f9fa; }
.random-table select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  outline: none;
}
.random-table input[type=number] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
}
.avail-tag {
  display: inline-block;
  padding: 2px 6px;
  background: #f1f3f4;
  color: #5f6368;
  border-radius: 4px;
  font-size: 11px;
  margin-right: 4px;
  white-space: nowrap;
}
.remove-row-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--google-red);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.2s;
}
.remove-row-btn:hover { background: #fde8e8; }
.modal-header-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; }
.sync-placeholder { text-align:center; padding:40px; border:2px dashed var(--border); border-radius:12px; color:var(--text-dim); }

/* ── SUMMARY DASHBOARD ──────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding-bottom: 40px;
}
.chap-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(60,64,67,0.1);
}
.chap-summary-card:hover {
  box-shadow: 0 4px 12px rgba(60,64,67,0.15);
  transform: translateY(-2px);
  border-color: var(--google-blue);
}
.chap-summary-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.4;
  height: 40px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.chap-stat-row {
  display: flex;
  gap: 24px;
  align-items: center;
}
.stat-circle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.stat-circle .circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
}
.stat-circle.reg .circle {
  background: #e8f0fe;
  color: #1a73e8;
  border: 2px solid #aecbfa;
}
.stat-circle.mcq .circle {
  background: #e6f4ea;
  color: #137333;
  border: 2px solid #ceead6;
}
.stat-circle label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}
