/* ═══════════════════════════════════════════════════════════════
   PowerMail Webmail UI – 捲動修復 + 功能中心排版
   ═══════════════════════════════════════════════════════════════ */

/* ── Roundcube Elastic 捲動修復（所有設定頁）── */
body.task-settings #layout {
  min-height: 100vh !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

body.task-settings #layout-content {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  -webkit-overflow-scrolling: touch;
}

body.task-settings #layout-content .formcontent,
body.task-settings #layout-content .formcontainer,
body.task-settings #layout-content #preferences-details {
  overflow: visible !important;
  height: auto !important;
  max-height: none !important;
}

html.pm-powermail-scroll,
html.pm-powermail-scroll body {
  height: 100% !important;
  overflow: auto !important;
  overflow-x: hidden !important;
}

body.pm-powermail-page,
body.task-settings.pm-powermail-page {
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

body.pm-powermail-page #layout {
  display: flex !important;
  flex-direction: row !important;
  align-items: stretch !important;
  min-height: 100vh !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

body.pm-powermail-page #layout-sidebar,
body.pm-powermail-page #layout-menu {
  flex: 0 0 auto !important;
  height: auto !important;
  min-height: 100vh !important;
}

body.pm-powermail-page #layout-list {
  flex: 0 0 220px !important;
  max-width: 260px !important;
  height: auto !important;
  min-height: 100vh !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

body.pm-powermail-page #layout-content {
  flex: 1 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  height: auto !important;
  min-height: 100vh !important;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

body.pm-powermail-page #layout-content .formcontent,
body.pm-powermail-page #layout-content .formcontainer,
body.pm-powermail-page #layout-content #preferences-details,
body.pm-powermail-page #layout-content .content,
body.pm-powermail-page #layout-content .iframe-wrapper,
body.pm-powermail-page .propform,
body.pm-powermail-page .boxfooter {
  overflow: visible !important;
  height: auto !important;
  max-height: none !important;
}

body.pm-powermail-page #layout-content > .header {
  flex-shrink: 0;
}

/* 浮動按鈕 */
#powermail-center-fixed {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9999;
  background: linear-gradient(135deg, #1a73e8 0%, #1558b0 100%);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(26, 115, 232, 0.35);
  font-weight: 600;
  font-size: 13px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#powermail-center-fixed:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(26, 115, 232, 0.45);
  color: #fff;
}

/* ── 公佈欄跑馬燈 ── */
#pm-marquee {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9998;
  background: linear-gradient(90deg, #fff8e1, #fffde7);
  border-bottom: 1px solid #f0d78c;
  overflow: hidden;
  white-space: nowrap;
  height: 30px;
  line-height: 30px;
  font-size: 13px;
}
.pm-marquee-track {
  display: inline-block;
  animation: pm-marquee-scroll linear infinite;
  padding-right: 100%;
}
body.pm-has-marquee { padding-top: 30px; }
@keyframes pm-marquee-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

.taskmenu a.button-powermail,
.taskmenu a.button-pmcal { display: inline-block; }

/* ═══════════════════════════════════════════════════════════════
   功能中心主版面
   ═══════════════════════════════════════════════════════════════ */
.pm-hub {
  --pm-primary: #1a73e8;
  --pm-primary-dark: #1558b0;
  --pm-surface: #ffffff;
  --pm-bg: #f4f6f9;
  --pm-border: #e2e8f0;
  --pm-text: #1e293b;
  --pm-muted: #64748b;
  --pm-radius: 12px;
  --pm-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);

  box-sizing: border-box;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 4px 48px;
  color: var(--pm-text);
  font-size: 14px;
  line-height: 1.55;
}

.pm-hub *, .pm-hub *::before, .pm-hub *::after { box-sizing: border-box; }

/* 頁首 */
.pm-hub-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--pm-border);
}

.pm-hub-title h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--pm-text);
}

.pm-hub-sub {
  margin: 0;
  color: var(--pm-muted);
  font-size: 13px;
}

.pm-hub-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 分頁導覽 */
.pm-hub-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
  padding: 4px;
  background: var(--pm-bg);
  border-radius: 10px;
  border: 1px solid var(--pm-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.pm-hub-nav a,
.pm-hub-nav button.pm-tab {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--pm-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.pm-hub-nav a:hover,
.pm-hub-nav button.pm-tab:hover {
  background: rgba(26, 115, 232, 0.08);
  color: var(--pm-primary);
}

.pm-hub-nav a.active,
.pm-hub-nav button.pm-tab.active {
  background: var(--pm-surface);
  color: var(--pm-primary);
  box-shadow: var(--pm-shadow);
  font-weight: 600;
}

.pm-hub-nav .pm-tab-icon { font-size: 15px; line-height: 1; }

/* 分頁內容 */
.pm-hub-panels { position: relative; }

.pm-hub-panel {
  display: none;
  animation: pm-fade-in 0.2s ease;
}
.pm-hub-panel.active { display: block; }

@keyframes pm-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 卡片 */
.pm-card {
  background: var(--pm-surface);
  border: 1px solid var(--pm-border);
  border-radius: var(--pm-radius);
  box-shadow: var(--pm-shadow);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.pm-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--pm-border);
}

.pm-card-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.pm-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.pm-card-icon.blue { background: #e8f0fe; }
.pm-card-icon.green { background: #e6f4ea; }
.pm-card-icon.amber { background: #fef7e0; }
.pm-card-icon.purple { background: #f3e8fd; }

.pm-card-desc {
  margin: 0 0 16px;
  color: var(--pm-muted);
  font-size: 13px;
}

/* 表單 */
.pm-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
}

.pm-field { margin-bottom: 0; }
.pm-field.pm-field-wide { grid-column: 1 / -1; }

.pm-field label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--pm-text);
}

.pm-field .pm-hint {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--pm-muted);
  margin-top: 4px;
}

.pm-field input[type="url"],
.pm-field input[type="email"],
.pm-field input[type="search"],
.pm-field input[type="text"],
.pm-field textarea {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--pm-border);
  border-radius: 8px;
  font: inherit;
  color: var(--pm-text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pm-field input:focus,
.pm-field textarea:focus {
  outline: none;
  border-color: var(--pm-primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.pm-field textarea { min-height: 96px; resize: vertical; }

.pm-form-actions {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--pm-border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* 按鈕 */
.pm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--pm-border);
  background: var(--pm-surface);
  color: var(--pm-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.pm-btn:hover {
  background: var(--pm-bg);
  color: var(--pm-text);
  text-decoration: none;
}

.pm-btn-primary,
.pm-btn.mainaction {
  background: var(--pm-primary) !important;
  border-color: var(--pm-primary) !important;
  color: #fff !important;
}
.pm-btn-primary:hover,
.pm-btn.mainaction:hover {
  background: var(--pm-primary-dark) !important;
  border-color: var(--pm-primary-dark) !important;
  color: #fff !important;
}

.pm-btn-outline {
  background: transparent;
  border-color: var(--pm-primary);
  color: var(--pm-primary);
}
.pm-btn-outline:hover {
  background: rgba(26, 115, 232, 0.08);
}

.pm-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 雙欄資訊區 */
.pm-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* 表格 */
.pm-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--pm-border);
  border-radius: 8px;
}

.pm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pm-table th,
.pm-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--pm-border);
}

.pm-table th {
  background: var(--pm-bg);
  font-weight: 600;
  color: var(--pm-muted);
  font-size: 12px;
  text-transform: none;
}

.pm-table tr:last-child td { border-bottom: none; }
.pm-table tbody tr:hover { background: #f8fafc; }

/* 空狀態 */
.pm-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--pm-muted);
  background: var(--pm-bg);
  border-radius: 8px;
  border: 1px dashed var(--pm-border);
}

.pm-empty-icon { font-size: 28px; margin-bottom: 8px; opacity: 0.7; }

.pm-meta {
  font-size: 12px;
  color: var(--pm-muted);
}

/* 公佈欄 */
.pm-bulletin-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pm-bulletin-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--pm-border);
}
.pm-bulletin-list li:last-child { border-bottom: none; }

.pm-bulletin-list strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
  color: var(--pm-text);
}

/* LDAP */
.pm-ldap-params {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pm-ldap-params th {
  text-align: left;
  width: 130px;
  padding: 8px 12px 8px 0;
  color: var(--pm-muted);
  font-weight: 500;
  vertical-align: top;
}

.pm-ldap-params td { padding: 8px 0; }

.pm-ldap-params code {
  display: block;
  word-break: break-all;
  background: var(--pm-bg);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid var(--pm-border);
}

.pm-ldap-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.pm-ldap-search {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pm-ldap-search input {
  flex: 1 1 200px;
  padding: 9px 12px;
  border: 1px solid var(--pm-border);
  border-radius: 8px;
  font: inherit;
}

#pm-ldap-results { margin-top: 12px; }

/* 舊版相容 */
.pm-section-title { display: none; }
.pm-cal-empty { color: var(--pm-muted); }
.pm-cal-meta { font-size: 12px; color: var(--pm-muted); }
.pm-ldap-panel { all: unset; }
.pm-ldap-hint { font-size: 13px; color: var(--pm-muted); margin: 8px 0; }
.pm-ldap-tools { display: contents; }

/* ═══════════════════════════════════════════════════════════════
   行事曆頁
   ═══════════════════════════════════════════════════════════════ */
.pm-cal-page .pm-hub-header { margin-bottom: 16px; }

#pmcal {
  margin-top: 8px;
  background: var(--pm-surface);
  border: 1px solid var(--pm-border);
  border-radius: var(--pm-radius);
  padding: 16px;
  box-shadow: var(--pm-shadow);
}

.pmcal-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.pmcal-nav, .pmcal-views {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.pmcal-title { font-weight: 600; margin-left: 8px; font-size: 15px; }

.pmcal-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.pmcal-grid th, .pmcal-grid td {
  border: 1px solid var(--pm-border);
  vertical-align: top;
  padding: 4px;
}

.pmcal-cell { height: 88px; }
.pmcal-cell.off { background: #f8fafc; color: #94a3b8; }
.pmcal-cell.today { background: #e8f0fe; }

.pmcal-daynum { font-size: 12px; font-weight: 600; }

.pmcal-ev {
  font-size: 11px;
  color: #fff;
  padding: 2px 5px;
  border-radius: 4px;
  margin-top: 2px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pmcal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.pmcal-modal {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  width: min(480px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.pmcal-modal h3 { margin: 0 0 14px; font-size: 17px; }
.pmcal-modal label { display: block; margin: 10px 0; font-size: 13px; font-weight: 500; }
.pmcal-modal input, .pmcal-modal textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--pm-border);
  border-radius: 6px;
  margin-top: 4px;
}

.pmcal-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }

.pmcal-toolbar .btn,
.pmcal-actions .btn {
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--pm-border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.pmcal-toolbar .btn.active { background: var(--pm-primary); color: #fff; border-color: var(--pm-primary); }
.pmcal-toolbar .btn.primary, .pmcal-actions .btn.primary { background: var(--pm-primary); color: #fff; border: none; }
.pmcal-actions .btn.danger { background: #d93025; color: #fff; border: none; }

/* ═══════════════════════════════════════════════════════════════
   響應式
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .pm-form-grid,
  .pm-split {
    grid-template-columns: 1fr;
  }

  body.pm-powermail-page #layout-list {
    flex: 0 0 180px !important;
  }
}

@media (max-width: 640px) {
  .pm-hub { padding-bottom: 72px; }

  .pm-hub-header { flex-direction: column; }

  .pm-hub-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .pm-hub-nav a,
  .pm-hub-nav button.pm-tab {
    flex-shrink: 0;
  }

  body.pm-powermail-page #layout-list {
    display: none;
  }

  .pmcal-cell { height: 64px; }
}
