* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #f0f2f8;
    color: #1a1a2e;
    font-size: 14px;
    display: flex;
    flex-direction: column;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 220px;
    height: 100%;
    background: #1a237e;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sb-logo {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.sb-logo .l1 {
    font-size: 15px;
    font-weight: 700;
    color: white;
}

.sb-logo .l2 {
    font-size: 11px;
    color: rgba(255, 255, 255, .5);
    margin-top: 2px;
}

.sb-nav {
    padding: 12px 0;
    flex: 1;
    overflow-y: auto;
}

.sb-section {
    font-size: 10px;
    font-weight: 700;
    color: rgba(255, 255, 255, .35);
    padding: 12px 20px 4px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.sb-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    font-size: 13px;
    color: rgba(255, 255, 255, .7);
    cursor: pointer;
    transition: all .15s;
    border-left: 3px solid transparent;
}

.sb-item:hover {
    background: rgba(255, 255, 255, .07);
    color: white;
}

.sb-item.active {
    background: rgba(255, 255, 255, .12);
    color: white;
    border-left-color: #7c4dff;
    font-weight: 500;
}

.sb-badge {
    margin-left: auto;
    background: #e53935;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
}

.sb-user {
    padding: 14px 20px;
    border-top: 1px solid rgba(255, 255, 255, .1);
}

.sb-user .role {
    font-size: 10px;
    color: rgba(255, 255, 255, .4);
    margin-bottom: 2px;
}

.sb-user .name {
    font-size: 13px;
    color: white;
    font-weight: 500;
}

.topbar {
    position: fixed;
    top: 0;
    left: 220px;
    right: 0;
    height: 52px;
    background: white;
    border-bottom: 1px solid #e8eaf6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 90;
}

.topbar .page-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a237e;
}

.topbar .actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.date-range {
    font-size: 12px;
    color: #666;
    background: #f5f5f5;
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.notif-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 16px;
}

.notif-dot {
    width: 8px;
    height: 8px;
    background: #e53935;
    border-radius: 50%;
    position: absolute;
    top: 6px;
    right: 6px;
    border: 1.5px solid white;
}

.main-scroll {
    position: fixed;
    top: 52px;
    left: 220px;
    right: 0;
    bottom: 0;
    overflow-y: auto;
}

.content {
    padding: 24px;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

#mdeditor.panel {
    padding: 0;
}

#mdeditor.panel.active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.md-editor-layout {
    display: grid;
    grid-template-columns: 200px 1fr 1fr;
    flex: 1;
    min-height: 0;
    background: white;
    border-top: 1px solid #e8eaf6;
}

.md-nav {
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.md-nav-head {
    padding: 14px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #1a237e;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.md-nav-item {
    padding: 10px 16px;
    font-size: 12px;
    cursor: pointer;
    border-left: 3px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #444;
    transition: all .15s;
}

.md-nav-item:hover {
    background: #f5f7ff;
    color: #1a237e;
}

.md-nav-item.active {
    background: #ede7f6;
    color: #4a148c;
    border-left-color: #7c4dff;
    font-weight: 500;
}

.md-nav-item .nav-badge {
    margin-left: auto;
    font-size: 9px;
    background: #e8eaf6;
    color: #666;
    padding: 1px 6px;
    border-radius: 8px;
}

.md-nav-spacer {
    flex: 1;
}

.version-row {
    padding: 10px 16px;
    font-size: 11px;
    color: #888;
    border-top: 1px solid #eee;
    background: #fafafa;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.version-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #43a047;
    flex-shrink: 0;
}

.md-editor-col {
    display: flex;
    flex-direction: column;
    border-right: 1px solid #eee;
    min-height: 0;
    overflow: hidden;
}

.md-preview-col {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.md-col-head {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    color: #888;
    background: #fafafa;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    letter-spacing: .05em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.md-col-head .head-right {
    display: flex;
    gap: 8px;
}

.md-col-head button {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
    background: white;
    cursor: pointer;
    color: #555;
    transition: all .1s;
}

.md-col-head button:hover {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
}

.md-col-head button.primary {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
}

.md-col-head button.primary:hover {
    background: #283593;
}

.md-textarea {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Fira Mono', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.7;
    padding: 16px;
    background: #fdfdfd;
    color: #2d2d2d;
    overflow-y: auto;
}

.md-preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    font-size: 13px;
    line-height: 1.75;
    color: #333;
}

.md-preview-body h1 {
    font-size: 18px;
    font-weight: 700;
    color: #1a237e;
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e8eaf6;
}

.md-preview-body h2 {
    font-size: 15px;
    font-weight: 600;
    color: #283593;
    margin: 20px 0 8px;
}

.md-preview-body h3 {
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin: 14px 0 6px;
}

.md-preview-body p {
    margin: 0 0 10px;
}

.md-preview-body ul,
.md-preview-body ol {
    padding-left: 20px;
    margin: 0 0 10px;
}

.md-preview-body li {
    margin: 3px 0;
}

.md-preview-body code {
    background: #f0f2ff;
    color: #5c35c9;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    font-family: monospace;
}

.md-preview-body pre {
    background: #f4f4f8;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
    margin: 10px 0;
    overflow-x: auto;
}

.md-preview-body pre code {
    background: none;
    color: #333;
    padding: 0;
    font-size: 12px;
}

.md-preview-body strong {
    color: #1a237e;
}

.md-preview-body blockquote {
    border-left: 3px solid #7c4dff;
    padding: 6px 14px;
    background: #f5f0ff;
    border-radius: 0 6px 6px 0;
    margin: 10px 0;
    color: #555;
    font-size: 12px;
}

.md-preview-body hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 16px 0;
}

.md-preview-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 10px 0;
}

.md-preview-body th {
    background: #e8eaf6;
    padding: 7px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    color: #333;
}

.md-preview-body td {
    padding: 7px 12px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
}

.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.metric-card {
    background: white;
    border-radius: 10px;
    padding: 16px 18px;
    border: 1px solid #e8eaf6;
}

.metric-card .ml {
    font-size: 11px;
    color: #888;
    margin-bottom: 6px;
}

.metric-card .mv {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 4px;
}

.metric-card .mg {
    font-size: 11px;
}

.mg.up {
    color: #2e7d32;
}

.mg.dn {
    color: #c62828;
}

.mg.neutral {
    color: #888;
}

.mc-blue .mv {
    color: #1a237e;
}

.mc-green .mv {
    color: #2e7d32;
}

.mc-purple .mv {
    color: #4a148c;
}

.mc-red .mv {
    color: #c62828;
}

.mc-orange .mv {
    color: #e65100;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.card {
    background: white;
    border-radius: 10px;
    border: 1px solid #e8eaf6;
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #f0f0f0;
}

.card-header .ch-title {
    font-size: 14px;
    font-weight: 600;
    color: #1a237e;
}

.card-header .ch-sub {
    font-size: 11px;
    color: #888;
}

.card-body {
    padding: 16px 18px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th {
    padding: 9px 14px;
    text-align: left;
    color: #888;
    font-weight: 600;
    font-size: 11px;
    border-bottom: 1px solid #f0f0f0;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.data-table td {
    padding: 9px 14px;
    border-bottom: 1px solid #f9f9f9;
    color: #333;
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: #fafbff;
}

.av-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.av-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.pill {
    display: inline-block;
    font-size: 10px;
    padding: 2px 9px;
    border-radius: 10px;
    font-weight: 600;
}

.pill.ok {
    background: #e8f5e9;
    color: #2e7d32;
}

.pill.warn {
    background: #fff3e0;
    color: #e65100;
}

.pill.error {
    background: #ffebee;
    color: #c62828;
}

.pill.idle {
    background: #f5f5f5;
    color: #666;
}

.bar-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bar-bg {
    flex: 1;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 3px;
}

.bar-lbl {
    font-size: 11px;
    color: #555;
    width: 32px;
    text-align: right;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid #f5f5f5;
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.ai-red {
    background: #ffebee;
}

.ai-yellow {
    background: #fff8e1;
}

.ai-blue {
    background: #e3f2fd;
}

.at1 {
    font-size: 12px;
    font-weight: 500;
    color: #222;
}

.at2 {
    font-size: 11px;
    color: #888;
    margin-top: 1px;
}

.alert-time {
    font-size: 10px;
    color: #bbb;
    margin-left: auto;
    white-space: nowrap;
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid #f5f5f5;
}

.rank-item:last-child {
    border-bottom: none;
}

.rank-num {
    width: 20px;
    font-size: 12px;
    font-weight: 700;
    color: #bbb;
    text-align: center;
}

.rank-num.top {
    color: #ffa000;
}

.rank-bar-bg {
    width: 80px;
    height: 5px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
}

.rank-bar-fill {
    height: 100%;
    background: #7c4dff;
    border-radius: 3px;
}

.donut-wrap {
    display: flex;
    align-items: center;
    gap: 20px;
}

.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dl-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #444;
}

.dl-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.dl-pct {
    margin-left: auto;
    font-weight: 600;
    color: #222;
    padding-left: 12px;
}

.ind-metrics {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.ind-metric {
    background: white;
    border-radius: 8px;
    padding: 12px 14px;
    border: 1px solid #e8eaf6;
    text-align: center;
}

.ind-metric .iml {
    font-size: 10px;
    color: #888;
    margin-bottom: 4px;
}

.ind-metric .imv {
    font-size: 20px;
    font-weight: 700;
}

.hm-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.hm-cell {
    aspect-ratio: 1;
    border-radius: 3px;
}

.hm-lbl {
    font-size: 10px;
    color: #888;
    text-align: center;
}

.hm-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    margin-bottom: 4px;
}

select.styled {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 12px;
    background: white;
    color: #333;
    cursor: pointer;
}

.stat-bar {
    height: 7px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 4px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    height: 130px;
    padding-bottom: 4px;
}

.chart-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.chart-col .b1 {
    border-radius: 4px 4px 0 0;
    width: 100%;
}

.chart-col .lbl {
    font-size: 10px;
    color: #888;
}

.legend-row {
    display: flex;
    gap: 14px;
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #555;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* Tiptap toolbar */
.tt-toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 10px;
  border-bottom: 1px solid #eee;
  background: #fafafa;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tt-toolbar button {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  background: white;
  cursor: pointer;
  color: #444;
  transition: all .1s;
  line-height: 1.5;
}

.tt-toolbar button:hover {
  background: #1a237e;
  color: white;
  border-color: #1a237e;
}

.tt-sep {
  width: 1px;
  height: 14px;
  background: #ddd;
  margin: 0 3px;
  flex-shrink: 0;
}

/* Tiptap / ProseMirror editor */
#tiptap-editor {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

#tiptap-editor .ProseMirror {
  min-height: 100%;
  padding: 20px 24px;
  outline: none;
  font-size: 13px;
  line-height: 1.75;
  color: #333;
  cursor: text;
}

#tiptap-editor .ProseMirror h1 {
  font-size: 18px;
  font-weight: 700;
  color: #1a237e;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e8eaf6;
}

#tiptap-editor .ProseMirror h2 {
  font-size: 15px;
  font-weight: 600;
  color: #283593;
  margin: 20px 0 8px;
}

#tiptap-editor .ProseMirror h3 {
  font-size: 13px;
  font-weight: 600;
  color: #444;
  margin: 14px 0 6px;
}

#tiptap-editor .ProseMirror p {
  margin: 0 0 10px;
}

#tiptap-editor .ProseMirror ul,
#tiptap-editor .ProseMirror ol {
  padding-left: 20px;
  margin: 0 0 10px;
}

#tiptap-editor .ProseMirror li {
  margin: 3px 0;
}

#tiptap-editor .ProseMirror code {
  background: #f0f2ff;
  color: #5c35c9;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-family: monospace;
}

#tiptap-editor .ProseMirror pre {
  background: #f4f4f8;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 12px;
  margin: 10px 0;
  overflow-x: auto;
}

#tiptap-editor .ProseMirror pre code {
  background: none;
  color: #333;
  padding: 0;
  font-size: 12px;
}

#tiptap-editor .ProseMirror strong {
  color: #1a237e;
}

#tiptap-editor .ProseMirror blockquote {
  border-left: 3px solid #7c4dff;
  padding: 6px 14px;
  background: #f5f0ff;
  border-radius: 0 6px 6px 0;
  margin: 10px 0;
  color: #555;
  font-size: 12px;
}

#tiptap-editor .ProseMirror hr {
  border: none;
  border-top: 1px solid #eee;
  margin: 16px 0;
}

#tiptap-editor .ProseMirror table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 10px 0;
}

#tiptap-editor .ProseMirror th {
  background: #e8eaf6;
  padding: 7px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: #333;
}

#tiptap-editor .ProseMirror td {
  padding: 7px 12px;
  border-bottom: 1px solid #f0f0f0;
  color: #444;
}

#tiptap-editor .ProseMirror p.is-editor-empty:first-child::before {
  content: '在這裡直接輸入或在左側編輯 Markdown…';
  color: #bbb;
  pointer-events: none;
  float: left;
  height: 0;
}

.save-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #2e7d32;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    display: none;
    z-index: 999;
}