:root {
  --pw-red: #e51c24;
  --pw-red-hover: #c41219;
  --pw-red-active: #9e0e14;
  --pw-red-subtle: #fef2f2;
  --pw-red-border: #fca5a5;

  --pw-sheet-green: #107c41;
  --pw-sheet-hover: #0b552c;
  --pw-sheet-subtle: #f0fdf4;

  --pw-bg-canvas: #f8fafc;
  --pw-bg-surface: #ffffff;
  --pw-bg-subtle: #f1f5f9;
  --pw-bg-hover: #e2e8f0;

  --pw-text-primary: #0f172a;
  --pw-text-secondary: #475569;
  --pw-text-muted: #94a3b8;

  --pw-border: #e2e8f0;
  --pw-border-strong: #cbd5e1;

  --pw-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pw-font-urdu: "Jameel Noori Nastaleeq", "Noto Nastaliq Urdu", "Urdu Typesetting", "Segoe UI", sans-serif;
  --pw-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --pw-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --pw-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --pw-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

body {
  font-family: var(--pw-font-sans);
  background-color: var(--pw-bg-canvas);
  color: var(--pw-text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

/* App Shell */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--pw-bg-surface);
  border-bottom: 1px solid var(--pw-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  height: 56px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  background: var(--pw-red);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--pw-text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-by {
  font-size: 11px;
  color: var(--pw-text-muted);
  font-weight: 500;
}

.brand-by a {
  color: var(--pw-red);
  font-weight: 600;
}

/* Ribbon Toolbar */
.ribbon-toolbar {
  background: var(--pw-bg-surface);
  border-bottom: 1px solid var(--pw-border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ribbon-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  border-right: 1px solid var(--pw-border);
}

.ribbon-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--pw-text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 28px;
  height: 28px;
  transition: all 0.15s ease;
}

.ribbon-btn:hover {
  background: var(--pw-bg-subtle);
  color: var(--pw-text-primary);
}

.ribbon-btn.active {
  background: var(--pw-red-subtle);
  color: var(--pw-red);
  border-color: var(--pw-red-border);
}

.ribbon-select {
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--pw-border);
  border-radius: 4px;
  background: var(--pw-bg-surface);
  color: var(--pw-text-primary);
  outline: none;
}

/* Page Layout for Document Editor */
.editor-workspace {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 56px - 32px);
  padding: 24px;
  align-items: center;
  background-color: var(--pw-bg-canvas);
}

.page-paper {
  width: 100%;
  max-width: 816px; /* A4 width at 96 DPI */
  min-height: 1056px; /* A4 height */
  background: var(--pw-bg-surface);
  box-shadow: var(--pw-shadow-md);
  border: 1px solid var(--pw-border);
  border-radius: 4px;
  padding: 72px; /* 0.75in margins */
  margin-bottom: 32px;
  outline: none;
  font-size: 15px;
  line-height: 1.6;
}

.page-paper:focus {
  border-color: #94a3b8;
}

/* RTL Support */
.rtl-mode, [dir="rtl"] {
  direction: rtl;
  text-align: right;
  font-family: var(--pw-font-urdu);
}

/* Sticky Metric Status Bar (Preserves Phase 1 Metric Guarantee) */
.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: var(--pw-bg-surface);
  border-top: 1px solid var(--pw-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 12px;
  color: var(--pw-text-secondary);
  z-index: 100;
}

.status-metrics {
  display: flex;
  gap: 16px;
}

.metric-pill {
  font-weight: 500;
}

.metric-pill span {
  color: var(--pw-text-primary);
  font-weight: 600;
}

/* Spreadsheet Grid Styles */
.sheet-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 32px);
  width: 100vw;
  overflow: hidden;
}

.formula-bar-container {
  display: flex;
  align-items: center;
  background: var(--pw-bg-surface);
  border-bottom: 1px solid var(--pw-border);
  padding: 4px 12px;
  gap: 8px;
  height: 36px;
}

.active-cell-box {
  width: 70px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--pw-border);
  padding: 4px;
  border-radius: 4px;
  background: var(--pw-bg-subtle);
}

.formula-input {
  flex: 1;
  border: 1px solid var(--pw-border);
  padding: 4px 8px;
  font-size: 13px;
  font-family: var(--pw-font-mono);
  border-radius: 4px;
  outline: none;
}

.grid-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #fff;
}

.sheet-table {
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.sheet-table th, .sheet-table td {
  border: 1px solid #e2e8f0;
  padding: 4px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-table th {
  background: #f1f5f9;
  color: #64748b;
  font-weight: 600;
  text-align: center;
  user-select: none;
}

.sheet-table th.col-header {
  height: 24px;
  min-width: 80px;
}

.sheet-table th.row-header {
  width: 45px;
  min-width: 45px;
}

.sheet-table td {
  background: #fff;
  height: 24px;
  cursor: cell;
}

.sheet-table td.selected {
  outline: 2px solid var(--pw-sheet-green);
  outline-offset: -1px;
}

/* Modals & Dropdowns */
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  border: 1px solid var(--pw-border);
  border-radius: 6px;
  box-shadow: var(--pw-shadow-lg);
  padding: 4px;
  display: none;
  z-index: 200;
  min-width: 180px;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--pw-text-primary);
  border-radius: 4px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background: var(--pw-bg-subtle);
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 44px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: var(--pw-shadow-lg);
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
