@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=Manrope:wght@500;600;700;800&display=swap');

:root {
  --ink: #172039;
  --ink-soft: #61708c;
  --ink-faint: #9ca8bd;
  --canvas: #edf3f8;
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --surface-muted: #f5f8fb;
  --line: rgba(94, 113, 148, .14);
  --line-strong: rgba(94, 113, 148, .22);
  --violet: #6954e8;
  --violet-deep: #4c39c2;
  --violet-wash: rgba(105, 84, 232, .12);
  --mint: #13b99a;
  --mint-wash: rgba(19, 185, 154, .13);
  --blue: #4b92ff;
  --orange: #f59a55;
  --rose: #ef6b89;
  --shadow-sm: 0 8px 24px rgba(47, 67, 103, .055);
  --shadow: 0 18px 48px rgba(47, 67, 103, .10), 0 2px 7px rgba(47, 67, 103, .04);
  --shadow-lift: 0 26px 60px rgba(47, 67, 103, .16), 0 7px 18px rgba(47, 67, 103, .06);
  --radius: 24px;
  --radius-md: 18px;
  --radius-sm: 13px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --display: 'Manrope', var(--font);
  --sidebar-w: 272px;
  --tabbar-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(circle at 10% 0%, rgba(139, 207, 255, .35), transparent 28rem),
    radial-gradient(circle at 95% 12%, rgba(190, 177, 255, .30), transparent 32rem),
    linear-gradient(135deg, #f4f8fb 0%, #edf2f8 46%, #f8f5ff 100%);
}
body::before, body::after { content: ''; position: fixed; pointer-events: none; filter: blur(12px); z-index: -1; border-radius: 999px; }
body::before { width: 23rem; height: 23rem; background: rgba(113, 231, 203, .12); left: 18%; bottom: -12rem; }
body::after { width: 27rem; height: 27rem; background: rgba(153, 128, 255, .11); right: -10rem; top: 38%; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(104, 120, 149, .26); border: 2px solid transparent; border-radius: 100px; background-clip: padding-box; }

/* App architecture */
.app-shell { min-height: 100vh; display: flex; padding: 18px; gap: 18px; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); min-height: calc(100vh - 36px);
  display: flex; flex-direction: column; padding: 18px 14px;
  background: rgba(252, 253, 255, .65); border: 1px solid rgba(255,255,255,.92);
  border-radius: 30px; box-shadow: var(--shadow); backdrop-filter: blur(26px) saturate(145%); -webkit-backdrop-filter: blur(26px) saturate(145%);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 8px 10px 34px; }
.sidebar-brand-icon, .auth-logo-icon {
  width: 43px; height: 43px; display: grid; place-items: center; color: #fff; font-size: 17px;
  border-radius: 15px; background: linear-gradient(135deg, #8c7aff 0%, #6351df 47%, #4231a8 100%);
  box-shadow: 0 10px 22px rgba(91, 70, 210, .30), inset 0 1px 1px rgba(255,255,255,.38);
}
.sidebar-brand-text { font: 800 18px/1 var(--display); letter-spacing: -.7px; }
.sidebar-menu { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.sidebar-link {
  position: relative; display: flex; align-items: center; gap: 13px; min-height: 48px; padding: 0 13px; overflow: hidden;
  border-radius: 15px; color: var(--ink-soft); font-size: 13px; font-weight: 700; text-decoration: none; transition: color .22s ease, transform .22s ease, background .22s ease;
}
.sidebar-link i { width: 21px; font-size: 16px; text-align: center; }
.sidebar-link:hover { color: var(--violet-deep); background: rgba(255,255,255,.60); transform: translateX(2px); }
.sidebar-link.active { color: #4635bb; background: linear-gradient(100deg, rgba(127, 109, 242, .18), rgba(157, 145, 255, .08)); box-shadow: inset 0 0 0 1px rgba(117, 96, 229, .12); }
.sidebar-link.active::before { content: ''; width: 4px; height: 22px; position: absolute; left: 0; border-radius: 10px; background: linear-gradient(#9d90ff, #5d48d9); }
.sidebar-logout { padding-top: 14px; border-top: 1px solid var(--line); }
.sidebar-logout .sidebar-link:hover { background: rgba(239, 107, 137, .10); color: #c54260; }
.theme-toggle { width: 100%; min-height: 43px; display: flex; align-items: center; gap: 12px; margin: 18px 0 22px; padding: 0 13px; border: 1px solid var(--line); border-radius: 14px; color: #61708c; background: rgba(255,255,255,.45); cursor: pointer; font: 700 12px/1 var(--font); transition: .2s ease; }
.theme-toggle:hover { color: #5140c8; border-color: rgba(105,84,232,.27); background: rgba(105,84,232,.08); transform: translateY(-1px); }
.theme-toggle i { width: 19px; text-align: center; }
.main-area { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { flex: 1; min-width: 0; padding: 22px 16px 34px 0; animation: contentFade .36s ease both; }
@keyframes contentFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes contentEnter { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* Header and feedback */
.page-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 0 0 22px; padding: 10px 10px 10px 12px; }
.page-header h1 { margin: 0; font: 800 clamp(25px, 3vw, 34px)/1.16 var(--display); letter-spacing: -1.35px; color: #172039; }
.page-header h1::after { content: ''; display: block; width: 34px; height: 4px; margin-top: 9px; border-radius: 10px; background: linear-gradient(90deg, #7261e9, #87d9eb); }
.flash { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; padding: 13px 16px; border: 1px solid; border-radius: 16px; font-size: 13px; font-weight: 700; box-shadow: var(--shadow-sm); animation: contentEnter .35s ease; }
.flash-success { color: #0b886f; background: rgba(230, 255, 247, .86); border-color: rgba(19, 185, 154, .24); }
.flash-warning { color: #a2680d; background: rgba(255,247,227,.90); border-color: rgba(245,154,85,.28); }
.flash-error { color: #c64a68; background: rgba(255,239,243,.88); border-color: rgba(239,107,137,.27); }

/* Reusable controls */
.btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px; border: 1px solid transparent; border-radius: 14px; cursor: pointer; font: 700 12px/1 var(--font); letter-spacing: .01em; text-decoration: none; transition: transform .2s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease; }
.btn i { font-size: 13px; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-primary { color: #fff; background: linear-gradient(135deg, #7b68ed 0%, #5943d4 56%, #4936ba 100%); box-shadow: 0 9px 20px rgba(79, 61, 192, .27), inset 0 1px 1px rgba(255,255,255,.24); }
.btn-primary:hover { box-shadow: 0 14px 27px rgba(79, 61, 192, .34), inset 0 1px 1px rgba(255,255,255,.26); }
.btn-secondary { color: #53617b; background: rgba(255,255,255,.76); border-color: rgba(120, 139, 170, .19); box-shadow: 0 5px 13px rgba(39,57,91,.05); }
.btn-secondary:hover { color: var(--violet-deep); border-color: rgba(104,84,232,.28); background: rgba(255,255,255,.96); }
.btn-danger { color: #d34e6d; background: rgba(255, 239, 243, .75); border-color: rgba(239,107,137,.18); }
.btn-danger:hover { background: rgba(255, 226, 233, .95); border-color: rgba(239,107,137,.36); }
.btn:disabled { opacity: .45; pointer-events: none; box-shadow: none; }
.btn-sm { min-height: 34px; min-width: 34px; padding: 0 11px; border-radius: 11px; }
.btn-block { width: 100%; }
.form-group { margin-bottom: 18px; }
.form-label { display: block; margin: 0 0 8px; color: #4e5b74; font-size: 12px; font-weight: 700; letter-spacing: .01em; }
.form-input, .form-select, .form-textarea {
  width: 100%; border: 1px solid rgba(113,132,164,.18); border-radius: 14px; outline: none; padding: 12px 14px; color: var(--ink); background: rgba(247,250,253,.84); box-shadow: inset 0 1px 2px rgba(54,73,109,.03); font: 500 14px/1.35 var(--font); transition: border-color .18s ease, box-shadow .18s ease, background .18s ease, transform .18s ease;
}
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: rgba(105,84,232,.31); background-color: #fff; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: rgba(105,84,232,.68); background-color: #fff; box-shadow: 0 0 0 4px rgba(105,84,232,.11), 0 8px 17px rgba(51,65,110,.06); }
.form-input::placeholder { color: #aab5c5; }
.form-select { appearance: none; padding-right: 42px; background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%2361708c' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; }
.form-textarea { min-height: 92px; resize: vertical; }
.form-readonly { opacity: .6; cursor: not-allowed; }

/* Universal floating surfaces */
.card, .stat-card, .range-bar-wrap, .filter-bar, .diary-stats-total {
  position: relative; background: var(--surface); border: 1px solid rgba(255,255,255,.91); border-radius: var(--radius); box-shadow: var(--shadow-sm); backdrop-filter: blur(18px) saturate(135%); -webkit-backdrop-filter: blur(18px) saturate(135%);
}
.card { padding: 24px; }
.card:hover, .stat-card:hover, .range-bar-wrap:hover { box-shadow: var(--shadow); }
.card-title { display: flex; align-items: center; gap: 9px; margin-bottom: 20px; color: #66738b; font-size: 10px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.card-title::before { content: ''; display: block; width: 8px; height: 8px; border-radius: 50%; background: linear-gradient(135deg, #917fff, #50c5dc); box-shadow: 0 0 0 4px rgba(105,84,232,.09); }

/* Dashboard */
.quick-form { display: flex; align-items: center; gap: 9px; padding: 5px; background: rgba(255,255,255,.67); border: 1px solid rgba(255,255,255,.9); border-radius: 17px; box-shadow: var(--shadow-sm); }
.quick-form input { width: 205px; padding: 9px 12px; border: 0; background: transparent; box-shadow: none; }
.quick-form input:focus { background: transparent; box-shadow: none; }
.quick-form .btn { min-height: 37px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 17px; }
.stat-card { min-height: 157px; padding: 22px; overflow: hidden; isolation: isolate; transition: transform .25s ease, box-shadow .25s ease; }
.stat-card::before { content: ''; position: absolute; z-index: -1; width: 130px; height: 130px; right: -47px; top: -58px; border-radius: 50%; background: radial-gradient(circle, rgba(130,111,248,.23), rgba(130,111,248,0) 68%); }
.stat-card:nth-child(2)::before { background: radial-gradient(circle, rgba(67,159,255,.22), rgba(67,159,255,0) 68%); }
.stat-card:nth-child(3)::before { background: radial-gradient(circle, rgba(17,193,156,.20), rgba(17,193,156,0) 68%); }
.stat-card:nth-child(4)::before { background: radial-gradient(circle, rgba(245,154,85,.22), rgba(245,154,85,0) 68%); }
.stat-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lift); }
.stat-label { margin-bottom: 25px; color: #7c88a0; font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.stat-value { color: var(--ink); font: 800 33px/1 var(--display); letter-spacing: -1.6px; font-variant-numeric: tabular-nums; }
.stat-value-unit { color: var(--ink-soft); font: 600 13px/1 var(--font); letter-spacing: 0; }
.range-bar-wrap { margin-bottom: 17px; padding: 21px 24px; overflow: hidden; }
.range-bar-wrap::after { content: ''; position: absolute; right: 10%; bottom: -45px; width: 150px; height: 90px; border-radius: 50%; background: rgba(20,190,158,.08); filter: blur(16px); }
.range-bar-header, .range-bar-footer { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 14px; }
.range-bar-header { margin-bottom: 15px; color: #627089; font-size: 13px; font-weight: 600; }
.range-bar-header strong { color: #0a9b82; font: 800 25px/1 var(--display); letter-spacing: -1px; }
.range-track { position: relative; z-index: 1; height: 12px; overflow: hidden; border-radius: 100px; background: linear-gradient(90deg, rgba(99,133,165,.12), rgba(99,133,165,.06)); box-shadow: inset 0 1px 3px rgba(55,74,110,.07); }
.range-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #15b99b, #46d4bc); box-shadow: 0 0 14px rgba(19,185,154,.42); transition: width 1.2s cubic-bezier(.22,1,.36,1); }
.range-bar-footer { margin-top: 11px; color: #8792a8; font-size: 11px; font-weight: 600; }
.charts-grid { display: grid; grid-template-columns: 1.24fr .88fr .88fr; gap: 17px; margin-bottom: 17px; }
.chart-card { min-height: 275px; padding: 23px 22px 17px; }
.chart-card canvas { max-height: 205px; width: 100% !important; }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; margin-bottom: 17px; }
.entry-list { display: flex; flex-direction: column; gap: 7px; }
.entry-row { display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 8px 11px; border: 1px solid transparent; border-radius: 14px; background: rgba(247,249,253,.72); transition: transform .2s ease, border-color .2s ease, background .2s ease; }
.entry-row:hover { transform: translateX(3px); border-color: rgba(105,84,232,.13); background: rgba(244,242,255,.75); }
.entry-time { width: 37px; color: #9aa5b8; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-sugar { min-width: 44px; font: 800 16px/1 var(--display); letter-spacing: -.5px; }
.entry-insulin, .entry-note { color: #718099; font-size: 12px; }
.entry-note { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-tag, .diary-card-badge, .product-badge, .meal-history-tags span { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 100px; color: #5c49d1; background: rgba(105,84,232,.10); font-size: 10px; font-weight: 800; white-space: nowrap; }
.entry-carbs { margin-left: auto; color: #53617b; font-size: 12px; font-weight: 700; }
.entry-bu { color: #0c9c83; font-size: 12px; font-weight: 800; }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 17px; }
.mini-stat { padding: 17px 14px; text-align: left; overflow: hidden; }
.mini-stat-label { display: block; margin-bottom: 8px; color: #8b96aa; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.mini-stat-value { color: var(--ink); font: 800 21px/1 var(--display); letter-spacing: -.8px; }

/* Diary and tables */
.filter-bar { margin-bottom: 16px; padding: 12px; }
.filter-row { display: flex; align-items: end; gap: 10px; }
.filter-row .form-group { min-width: 170px; margin: 0; }
.filter-row .btn { min-height: 43px; }
.heatmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 8px; }
.heatmap-cell { min-height: 38px; display: grid; place-items: center; border: 2px solid rgba(255,255,255,.78); border-radius: 12px; color: rgba(255,255,255,.92); font-size: 8px; font-weight: 800; box-shadow: 0 6px 13px rgba(38,55,86,.09); transition: transform .18s ease, filter .18s ease; }
.heatmap-cell:hover { transform: translateY(-3px) scale(1.05); filter: brightness(1.05); }
.diary-stats-total { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; padding: 15px 18px; color: #738098; font-size: 12px; font-weight: 600; }
.diary-stats-total strong { color: var(--ink); font-weight: 800; }
.diary-date-header { margin: 22px 0 9px 3px; color: #52607b; font: 800 13px/1 var(--display); letter-spacing: -.2px; }
.diary-table-wrap { overflow-x: auto; border: 1px solid rgba(255,255,255,.92); border-radius: 22px; background: rgba(255,255,255,.68); box-shadow: var(--shadow-sm); backdrop-filter: blur(16px); }
.diary-table { width: 100%; min-width: 640px; border-collapse: separate; border-spacing: 0; }
.diary-table th { padding: 14px 15px; color: #8792a6; background: rgba(247,249,253,.68); border-bottom: 1px solid var(--line); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-align: left; text-transform: uppercase; }
.diary-table td { padding: 13px 15px; color: #65738c; border-bottom: 1px solid rgba(103,123,157,.095); font-size: 12px; vertical-align: middle; }
.diary-table tbody tr { transition: background .18s ease; }
.diary-table tbody tr:hover { background: rgba(241,239,255,.60); }
.diary-table tbody tr:last-child td { border-bottom: 0; }
.diary-td-time { color: #8e9ab0 !important; font-weight: 700; font-variant-numeric: tabular-nums; }
.diary-td-sugar .sugar-color { font: 800 16px/1 var(--display); }
.diary-td-insulin, .diary-td-xe { font-weight: 700; }
.diary-td-xe { color: #0e9d84 !important; }
.diary-td-notes { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diary-td-actions { display: flex; justify-content: flex-end; gap: 6px; }
.diary-td-actions form { margin: 0; }
.diary-date-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 9px 0 2px; }
.diary-date-stat { padding: 6px 10px; border: 1px solid var(--line); border-radius: 100px; color: #7b879c; background: rgba(255,255,255,.50); font-size: 10px; font-weight: 600; }
.diary-date-stat strong { color: #40506b; font-weight: 800; }

/* Products, modal, calculator */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 15px; }
.product-card { min-height: 159px; display: flex; flex-direction: column; justify-content: space-between; padding: 19px; border: 1px solid rgba(255,255,255,.92); border-radius: 22px; background: rgba(255,255,255,.72); box-shadow: var(--shadow-sm); transition: transform .24s ease, box-shadow .24s ease; }
.product-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lift); }
.product-card-default { background: linear-gradient(145deg, rgba(248,247,255,.92), rgba(239,249,255,.78)); }
.product-name { margin-bottom: 8px; color: #2a3651; font: 800 16px/1.25 var(--display); letter-spacing: -.5px; }
.product-carbs { color: #6e7c94; font-size: 12px; font-weight: 600; }
.product-badge { margin-top: 12px; color: #168a78; background: var(--mint-wash); }
.product-actions { display: flex; gap: 7px; justify-content: flex-end; margin-top: 15px; }
.modal-overlay { position: fixed; z-index: 100; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(23,32,57,.10); opacity: 0; visibility: hidden; transition: opacity .24s ease, visibility .24s ease; }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content { width: min(100%, 455px); max-height: calc(100vh - 48px); overflow: auto; position: relative; padding: 30px; border: 1px solid rgba(255,255,255,.94); border-radius: 28px; background: rgba(255,255,255,.87); box-shadow: 0 28px 90px rgba(28,38,72,.27); backdrop-filter: blur(28px); transform: translateY(16px) scale(.98); transition: transform .28s cubic-bezier(.2,.8,.2,1); }
.modal-overlay.active .modal-content { transform: translateY(0) scale(1); }
.modal-close { position: absolute; right: 16px; top: 16px; width: 34px; height: 34px; border: 0; border-radius: 11px; color: #758299; background: #f2f5fa; cursor: pointer; transition: .18s ease; }
.modal-close:hover { color: #ca4b69; background: #ffeef2; transform: rotate(90deg); }
.modal-title { margin: 0 40px 25px 0; color: var(--ink); font: 800 23px/1.2 var(--display); letter-spacing: -1px; }
.calc-search-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px auto; gap: 12px; align-items: end; }
.calc-search-row .form-group { margin-bottom: 0; }
.search-wrap { position: relative; }
.suggestions-dropdown { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 7px); display: none; max-height: 220px; overflow: auto; padding: 6px; border: 1px solid rgba(255,255,255,.9); border-radius: 16px; background: rgba(255,255,255,.95); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.suggestions-dropdown.visible { display: block; }
.suggestion-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px; border-radius: 10px; color: #44516c; font-size: 12px; cursor: pointer; transition: background .15s ease; }
.suggestion-item:hover { background: rgba(105,84,232,.09); }
.suggestion-carbs { color: #0e9d84; font-weight: 800; white-space: nowrap; }
.calc-preview { display: flex; justify-content: space-between; gap: 16px; margin: 20px 0; padding: 13px 15px; border: 1px solid rgba(19,185,154,.17); border-radius: 15px; color: #5b6982; background: rgba(230,255,247,.58); font-size: 12px; }
.calc-preview strong { color: #0b927c; font: 800 18px/1 var(--display); }
.meal-items-list { display: flex; flex-direction: column; gap: 7px; margin: 21px 0; }
.meal-item-row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid rgba(103,123,157,.11); border-radius: 14px; background: rgba(248,250,253,.72); }
.meal-item-name { flex: 1; color: #40506b; font-size: 13px; font-weight: 800; }
.meal-item-detail { color: #8792a7; font-size: 11px; }
.calc-totals { margin: 20px 0; padding: 18px; border-radius: 19px; background: linear-gradient(135deg, rgba(110,91,233,.12), rgba(88,207,203,.11)); border: 1px solid rgba(105,84,232,.12); }
.calc-totals-title { margin-bottom: 13px; color: #5d4bc8; font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.calc-totals-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.calc-totals-grid div { min-width: 0; padding: 9px; border-radius: 12px; background: rgba(255,255,255,.52); text-align: center; }
.calc-totals-grid span { display: block; color: #7b88a0; font-size: 9px; font-weight: 700; }
.calc-totals-grid strong { display: block; margin-top: 4px; color: #35425c; font: 800 16px/1 var(--display); }
.meal-history-item { margin-bottom: 9px; padding: 14px; border: 1px solid rgba(103,123,157,.11); border-radius: 16px; background: rgba(249,251,254,.70); transition: background .18s ease; }
.meal-history-item:hover { background: rgba(244,242,255,.70); }
.meal-history-header { display: flex; align-items: center; gap: 11px; }
.meal-history-type { color: #40506b; font-weight: 800; }
.meal-history-date { color: #99a4b7; font-size: 11px; }
.meal-history-carbs { margin-left: auto; color: #52607a; font-weight: 800; }
.meal-history-bu { color: #0a9b82; font-weight: 800; }
.meal-history-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.meal-history-actions { display: flex; justify-content: end; gap: 6px; margin-top: 10px; }

/* Settings and auth */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 17px; }
.info-list { display: flex; flex-direction: column; }
.info-row { display: flex; justify-content: space-between; gap: 15px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.info-row:last-child { border-bottom: 0; }
.info-row-label, .text-muted { color: #8793a8; font-size: 12px; }
.info-row-value { color: #48566f; font-weight: 800; }
.info-status-active { padding: 3px 9px; border-radius: 100px; color: #0c917c; background: var(--mint-wash); font-size: 10px; font-weight: 800; }
.empty-state { padding: 20px; border: 1px dashed rgba(104,120,149,.23); border-radius: 15px; color: #9aa6b9; font-size: 12px; font-weight: 600; text-align: center; }
.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; overflow: auto; }
.auth-wrapper { width: min(100%, 460px); position: relative; }
.auth-wrapper::before { content: ''; position: absolute; z-index: -1; width: 330px; height: 330px; left: -100px; top: -100px; border-radius: 50%; background: radial-gradient(circle, rgba(113,93,238,.29), transparent 69%); filter: blur(13px); }
.auth-card { padding: 39px; border: 1px solid rgba(255,255,255,.9); border-radius: 30px; background: rgba(255,255,255,.73); box-shadow: 0 26px 70px rgba(42,59,96,.16); backdrop-filter: blur(25px) saturate(145%); }
.auth-logo { margin-bottom: 30px; text-align: center; }
.auth-logo-icon { margin: 0 auto 15px; width: 50px; height: 50px; border-radius: 18px; }
.auth-logo h1 { margin: 0; font: 800 27px/1 var(--display); letter-spacing: -1.3px; }
.auth-logo p { margin: 9px 0 0; color: #8792a7; font-size: 12px; font-weight: 600; }
.auth-form-title { margin-bottom: 21px; color: #34415c; font: 800 16px/1 var(--display); letter-spacing: -.4px; }
.auth-footer { margin-top: 20px; color: #8792a7; font-size: 12px; text-align: center; }
.auth-footer a { color: #5a46d0; font-weight: 800; text-decoration: none; }

/* Mobile navigation */
.tabbar { display: none; }
.sugar-color { color: var(--mint); }

/* Dark theme */
html[data-theme='dark'] {
  --ink: #edf2ff;
  --ink-soft: #aebbd1;
  --ink-faint: #7d8aa2;
  --surface: rgba(24, 33, 54, .76);
  --surface-solid: #1b263d;
  --surface-muted: #222e47;
  --line: rgba(173, 190, 220, .13);
  --line-strong: rgba(173, 190, 220, .22);
  --shadow-sm: 0 8px 25px rgba(0, 0, 0, .16);
  --shadow: 0 18px 48px rgba(0, 0, 0, .25), 0 2px 7px rgba(0, 0, 0, .12);
  --shadow-lift: 0 26px 60px rgba(0, 0, 0, .35), 0 7px 18px rgba(0, 0, 0, .12);
}
html[data-theme='dark'] body { background: radial-gradient(circle at 8% 0%, rgba(57, 108, 169, .33), transparent 30rem), radial-gradient(circle at 96% 10%, rgba(91, 68, 176, .31), transparent 34rem), linear-gradient(135deg, #101827 0%, #151d31 48%, #1a1934 100%); }
html[data-theme='dark'] body::before { background: rgba(20, 187, 156, .10); }
html[data-theme='dark'] body::after { background: rgba(134, 103, 246, .12); }
html[data-theme='dark'] .sidebar { background: rgba(20, 29, 48, .70); border-color: rgba(255,255,255,.09); }
html[data-theme='dark'] .sidebar-brand-text, html[data-theme='dark'] .page-header h1, html[data-theme='dark'] .stat-value, html[data-theme='dark'] .mini-stat-value, html[data-theme='dark'] .modal-title, html[data-theme='dark'] .auth-logo h1 { color: #f1f5ff; }
html[data-theme='dark'] .sidebar-link { color: #aab8ce; }
html[data-theme='dark'] .sidebar-link:hover { color: #c6bcff; background: rgba(255,255,255,.055); }
html[data-theme='dark'] .sidebar-link.active { color: #d0c9ff; background: linear-gradient(100deg, rgba(123,104,237,.29), rgba(157,145,255,.10)); }
html[data-theme='dark'] .theme-toggle { color: #b9c4d8; background: rgba(255,255,255,.045); }
html[data-theme='dark'] .theme-toggle:hover { color: #d8d2ff; background: rgba(123,104,237,.17); }
html[data-theme='dark'] .card, html[data-theme='dark'] .stat-card, html[data-theme='dark'] .range-bar-wrap, html[data-theme='dark'] .filter-bar, html[data-theme='dark'] .diary-stats-total, html[data-theme='dark'] .product-card, html[data-theme='dark'] .diary-table-wrap { border-color: rgba(255,255,255,.09); background: rgba(25, 35, 57, .74); }
html[data-theme='dark'] .product-card-default { background: linear-gradient(145deg, rgba(49,43,87,.80), rgba(25,52,72,.72)); }
html[data-theme='dark'] .quick-form, html[data-theme='dark'] .entry-row, html[data-theme='dark'] .meal-item-row, html[data-theme='dark'] .meal-history-item { background: rgba(35, 47, 72, .73); border-color: rgba(255,255,255,.06); }
html[data-theme='dark'] .entry-row:hover, html[data-theme='dark'] .meal-history-item:hover { background: rgba(70,57,126,.32); }
html[data-theme='dark'] .form-input, html[data-theme='dark'] .form-select, html[data-theme='dark'] .form-textarea { color: #ecf2ff; border-color: rgba(180,196,226,.15); background-color: rgba(12, 20, 36, .47); }
html[data-theme='dark'] .form-input:hover, html[data-theme='dark'] .form-select:hover, html[data-theme='dark'] .form-textarea:hover, html[data-theme='dark'] .form-input:focus, html[data-theme='dark'] .form-select:focus, html[data-theme='dark'] .form-textarea:focus { background-color: rgba(12, 20, 36, .75); }
html[data-theme='dark'] .form-select { background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23b8c4d8' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; background-size: 12px 8px; }
html[data-theme='dark'] .form-label, html[data-theme='dark'] .card-title, html[data-theme='dark'] .stat-label, html[data-theme='dark'] .product-carbs, html[data-theme='dark'] .entry-insulin, html[data-theme='dark'] .entry-note, html[data-theme='dark'] .info-row-label, html[data-theme='dark'] .text-muted { color: #aebbd1; }
html[data-theme='dark'] .btn-secondary { color: #c5d0e3; border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.065); }
html[data-theme='dark'] .btn-secondary:hover { color: #e1dcff; background: rgba(123,104,237,.16); }
html[data-theme='dark'] .diary-table th { color: #98a6bd; background: rgba(12,20,36,.32); border-color: rgba(255,255,255,.07); }
html[data-theme='dark'] .diary-table td { color: #b8c5d9; border-color: rgba(255,255,255,.07); }
html[data-theme='dark'] .diary-table tbody tr:hover { background: rgba(70,57,126,.27); }
html[data-theme='dark'] .diary-date-stat, html[data-theme='dark'] .calc-totals-grid div { color: #b8c5d9; border-color: rgba(255,255,255,.10); background: rgba(255,255,255,.055); }
html[data-theme='dark'] .diary-date-stat strong, html[data-theme='dark'] .info-row-value, html[data-theme='dark'] .meal-item-name, html[data-theme='dark'] .product-name, html[data-theme='dark'] .meal-history-type, html[data-theme='dark'] .calc-totals-grid strong { color: #e4eaff; }
html[data-theme='dark'] .modal-overlay { background: rgba(4, 8, 18, .38); }
html[data-theme='dark'] .modal-content, html[data-theme='dark'] .auth-card, html[data-theme='dark'] .suggestions-dropdown { border-color: rgba(255,255,255,.12); background: rgba(27, 38, 62, .94); }
html[data-theme='dark'] .modal-close { color: #b1bed2; background: rgba(255,255,255,.07); }
html[data-theme='dark'] .topbar, html[data-theme='dark'] .tabbar { background: rgba(20,29,48,.84); border-color: rgba(255,255,255,.09); }
html[data-theme='dark'] .topbar-title { color: #eef3ff; }
html[data-theme='dark'] .tab-link { color: #94a3bb; }
html[data-theme='dark'] .tab-link.active { color: #d0c8ff; background: rgba(123,104,237,.20); }
@media (max-width: 1120px) { .stats-grid { grid-template-columns: repeat(2,1fr); } .charts-grid { grid-template-columns: 1.2fr 1fr; } .charts-grid .chart-card:first-child { grid-column: span 2; } }
@media (max-width: 830px) {
  .app-shell { display: block; padding: 0; } .sidebar { display: none; } .main-area { min-height: 100vh; }
  .topbar { display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: calc(13px + var(--safe-t)) 18px 13px; background: rgba(250,252,255,.73); border-bottom: 1px solid rgba(255,255,255,.9); backdrop-filter: blur(22px); }
  .topbar-title { font: 800 17px/1 var(--display); letter-spacing: -.55px; }
  .theme-toggle-mobile { width: 38px; min-height: 38px; justify-content: center; margin: 0; padding: 0; border-radius: 12px; }
  .theme-toggle-mobile i { width: auto; }
  .content { padding: 19px 15px calc(var(--tabbar-h) + 22px + var(--safe-b)); }
  .tabbar { display: block; position: fixed; z-index: 50; left: 12px; right: 12px; bottom: calc(10px + var(--safe-b)); height: var(--tabbar-h); padding: 7px; border: 1px solid rgba(255,255,255,.9); border-radius: 22px; background: rgba(255,255,255,.82); box-shadow: 0 15px 40px rgba(40,57,90,.17); backdrop-filter: blur(23px) saturate(145%); }
  .tabbar-inner { height: 100%; display: flex; align-items: stretch; justify-content: space-between; }
  .tab-link { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border-radius: 15px; color: #8b97ab; font-size: 9px; font-weight: 700; text-decoration: none; transition: .2s ease; }
  .tab-link i { font-size: 17px; } .tab-link.active { color: #5844ca; background: rgba(105,84,232,.10); }
  .tab-link.active i { transform: translateY(-1px); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .page-header { align-items: stretch; flex-direction: column; min-height: 0; padding: 4px 3px; margin-bottom: 17px; } .page-header h1 { font-size: 27px; }
  .quick-form { width: 100%; } .quick-form input { width: auto; flex: 1; }
  .stats-grid, .mini-stats { gap: 10px; } .stat-card { min-height: 133px; padding: 17px; } .stat-label { margin-bottom: 20px; font-size: 9px; } .stat-value { font-size: 27px; }
  .charts-grid, .split-grid { grid-template-columns: 1fr; gap: 11px; margin-bottom: 11px; } .charts-grid .chart-card:first-child { grid-column: auto; } .chart-card { min-height: 252px; }
  .card { padding: 18px; } .range-bar-wrap { padding: 18px; } .range-bar-header strong { font-size: 21px; }
  .filter-row { align-items: stretch; flex-direction: column; } .filter-row .form-group { width: 100%; min-width: 0; } .filter-row .btn { width: 100%; }
  .calc-search-row { grid-template-columns: 1fr 100px; } .calc-search-row .btn { grid-column: span 2; width: 100%; }
  .calc-totals-grid { grid-template-columns: repeat(2,1fr); } .meal-history-header { flex-wrap: wrap; } .meal-history-carbs { margin-left: 0; }
  .modal-overlay { align-items: end; padding: 0; } .modal-content { max-height: 90vh; padding: 27px 20px calc(24px + var(--safe-b)); border-radius: 28px 28px 0 0; }
  .auth-page { padding: 15px; } .auth-card { padding: 30px 23px; border-radius: 26px; }
}
@media (max-width: 390px) { .stats-grid, .mini-stats { grid-template-columns: 1fr 1fr; } .stat-card { padding: 14px; } .stat-value { font-size: 23px; } .tab-link { font-size: 8px; } }
